D
DevynCJohnson
Guest
I have noticed that many people on the Internet ask about running Windows batch files on Linux. Unfortunately, many of the answers such people receive state that batch scripts cannot run on Linux. However, Linux users can indeed run batch files. Also, Windows batch files can be run on Windows like a native shell script.
First, the Linux system must have Wine installed. On most Linux systems, this requires the user to install the "wine" package. On some Debian-based systems, users may have conflicts with the "nvidia-libopencl1-331-updates" package. This can be fixed by installing "ocl-icd-opencl-dev" and its dependencies. The package manager should remove "nvidia-libopencl1-331-updates", if not, then the user must do so. If for some reason, Wine is not found in the repos, then either add this PPA (ppa:ubuntu-wine/ppa) or go to https://www.winehq.org/ and download the needed package.
Once Wine is installed, open a terminal and run "wineconsole cmd". This will open a separate Windows-Console window. From here, users can run various Windows terminal commands. Batch files can be run by typing "start FILENAME.bat".
Alternately, type "wine cmd" to run the Windows-Console in the Linux terminal.
When in the native Linux shell, the batch files can be executed by typing "wine cmd.exe /c FILENAME.bat" or any of the following ways.
wine cmd < FILENAME.bat
wine cmd.exe < FILENAME.bat
wine start FILENAME.bat
wine cmd /c FILENAME.bat
In the user's bashrc file (~/.bashrc), it may help to add the following lines for Linux shell scripting purposes.
At this point, many Linux users may find it difficult to need to open a terminal and run that command just to run a batch file. Thankfully, there are two ways to fix that problem.
The quickest fix is to add the line seen below to the alias file (~/.bash_aliases). Next, logout and log back in so that the alias file will re-initialize. Then, users can type "winbatch FILENAME.bat" to execute a batch file in a terminal.
The second alternative is to make batch files execute as if they were a native shell script. To do so, download Winescript at http://dcjtech.info/wp-content/uploads/2015/02/winescript-v2015.02.08.zip. Next, uncompress the file and be sure that the file is named "winescript". Then, with Root privileges, move the script to /usr/share/bin/ or /usr/bin/ by typing "mv ./winescript /usr/share/bin/winescript" in a terminal. Finally, make the file executable by running "chmod +x /usr/share/bin/winescript" with Root privileges.
If Winescript and Wine have been installed successfully, then the user must make two changes to batch files to make them act like native scripts. First, make "#!/usr/bin/env winescript" the first line (hashpling) in the batch file. Lastly, make the batch file executable by running "chmod +x ./FILENAME.bat". Now, the user can execute this Windows batch file natively on GNU/Linux.
Now that batch files can be used on Linux, it may help to know some general facts. "*.bat" is the extension that was first used in DOS. Later, Windows NT and OS/2 added "*.cmd". Some shells (like 4OS2) supported the "*.btm" extension.
Further Reading
http://en.wikipedia.org/wiki/Batch_file
First, the Linux system must have Wine installed. On most Linux systems, this requires the user to install the "wine" package. On some Debian-based systems, users may have conflicts with the "nvidia-libopencl1-331-updates" package. This can be fixed by installing "ocl-icd-opencl-dev" and its dependencies. The package manager should remove "nvidia-libopencl1-331-updates", if not, then the user must do so. If for some reason, Wine is not found in the repos, then either add this PPA (ppa:ubuntu-wine/ppa) or go to https://www.winehq.org/ and download the needed package.
Once Wine is installed, open a terminal and run "wineconsole cmd". This will open a separate Windows-Console window. From here, users can run various Windows terminal commands. Batch files can be run by typing "start FILENAME.bat".
Alternately, type "wine cmd" to run the Windows-Console in the Linux terminal.
When in the native Linux shell, the batch files can be executed by typing "wine cmd.exe /c FILENAME.bat" or any of the following ways.
wine cmd < FILENAME.bat
wine cmd.exe < FILENAME.bat
wine start FILENAME.bat
wine cmd /c FILENAME.bat
In the user's bashrc file (~/.bashrc), it may help to add the following lines for Linux shell scripting purposes.
Code:
export WINEPREFIX=$HOME/.wine/
export WINEHOME=$HOME/.wine/
# for 32-bit
export WINEARCH=win32
# for 64-bit
export WINEARCH=win64
At this point, many Linux users may find it difficult to need to open a terminal and run that command just to run a batch file. Thankfully, there are two ways to fix that problem.
The quickest fix is to add the line seen below to the alias file (~/.bash_aliases). Next, logout and log back in so that the alias file will re-initialize. Then, users can type "winbatch FILENAME.bat" to execute a batch file in a terminal.
Code:
alias winbatch="wine cmd /c "
The second alternative is to make batch files execute as if they were a native shell script. To do so, download Winescript at http://dcjtech.info/wp-content/uploads/2015/02/winescript-v2015.02.08.zip. Next, uncompress the file and be sure that the file is named "winescript". Then, with Root privileges, move the script to /usr/share/bin/ or /usr/bin/ by typing "mv ./winescript /usr/share/bin/winescript" in a terminal. Finally, make the file executable by running "chmod +x /usr/share/bin/winescript" with Root privileges.
If Winescript and Wine have been installed successfully, then the user must make two changes to batch files to make them act like native scripts. First, make "#!/usr/bin/env winescript" the first line (hashpling) in the batch file. Lastly, make the batch file executable by running "chmod +x ./FILENAME.bat". Now, the user can execute this Windows batch file natively on GNU/Linux.
Now that batch files can be used on Linux, it may help to know some general facts. "*.bat" is the extension that was first used in DOS. Later, Windows NT and OS/2 added "*.cmd". Some shells (like 4OS2) supported the "*.btm" extension.
Further Reading
http://en.wikipedia.org/wiki/Batch_file