- 1 year ago
Calling CMD and passing inputs to EXE from a Bash shell script (using Git Bash for Windows)
To call a command line executable (EXE) from a Bash shell script and pass inputs to it, you can use the wine
command if the EXE is a Windows executable.
Here is an example script that calls a Windows EXE called myprogram.exe
with two command line arguments and waits for the program to finish before continuing:
bash#!/bin/bash
wine "C:/path/to/myprogram.exe" arg1 arg2
wait
echo "myprogram.exe has finished"
In this script, wine
is used to execute myprogram.exe
and pass two arguments (arg1
and arg2
) to it. The wait
command is used to wait for myprogram.exe
to finish before the script continues. Finally, the script prints a message indicating that myprogram.exe
has finished.
Note that the path to myprogram.exe
should be given in Windows format (using forward slashes), and the arguments should be separated by spaces.
If the EXE is a native Linux executable, you can simply call it directly from the Bash shell script, without the need for wine
. Here is an example script that calls a Linux executable called myprogram
with two command line arguments and waits for the program to finish before continuing:
bash#!/bin/bash
/path/to/myprogram arg1 arg2
wait
echo "myprogram has finished"
In this script, /path/to/myprogram
is the path to the Linux executable, and the two arguments (arg1
and arg2
) are passed to it. The wait
command is used to wait for myprogram
to finish before the script continues. Finally, the script prints a message indicating that myprogram
has finished.