I have a sh/bash script that needs to call a batch file with parameters (parameters are file names and are given in DOS/Windows format).
Basically I have: script.sh
#!/bin/sh
declare var1=$1
declare var2=$2
dosomething var1 var2
...
<invoke batch script> var1 var2
...
dosomethingelse
I'm using GNU bash, version 3.1.0(3)-release (i686-pc-msys)
as the shell, on msysgit
The problem is that when i run from script:
$COMSPEC /c batchfile param1 param2
either I get an "empty prompt" which looks like bash, but no command result is displayed on the console, either cmd.exe
start, but doesn't execute the script.
I've tried quoting the params to bash like this:
$COMSPEC /c \"batchfile param1 param2\"
$COMSPEC /c \"\"batchfile param1 param2\"\"
$COMSPEC /c \"\"batchfile \"param1\" \"param2\"\"\"
But I didn't get any result.
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.
Or may be you write programs in Java and for each operating system you have a script to set up an environment (sh-script or cmd-script). If you need to do basically the same in Windows and in Linux, you can write only one script, that will work in both operating systems.
Execute Shell Script Files Open Command Prompt and navigate to the folder where the script file is available. Type Bash script-filename.sh and hit the enter key. It will execute the script, and depending on the file, you should see an output.
It seems that I needed to escape the space from the cmd param:
$COMSPEC \/c batch-file\ \"$var1\"\ \"$var2\"
or
$COMSPEC /c batch-file\ \"$var1\"\ \"$var2\"
I'm not sure whether the / from /c needs to be escaped, but it works fine both ways escaped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With