Reputation: 848
I need to call a batch file from inside CYGWIN however one of it's parameters is a path-like string containing semicolons. Normally in windows command line one could enclose that parameter in quotes (which would need to be trimmed later on). However this approach doesn't wok in cygwin
Example batch (echoes first 3 parameters)
echo %1
echo %2
echo %3
Windows cmd call
file.bat "a;b" c
Ouput
"a;b"
c
empty
Cygwin call
./file.bat "a;b" c
Output
a
b
c
Upvotes: 4
Views: 2809
Reputation: 128
Recent battles with quoting led me to another technique.
Create a temporary batch file and pass it to cmd. (I used "filex.bat" in this example).
echo 'call file.bat "a;b" c' > filex.bat ; cmd /c filex.bat ; rm filex.bat
Upvotes: 1
Reputation: 848
Including space anywhere inside quotes will ensure that parameter with semicolon or comma is passed correctly. Although I have to admit that I do not understand this behavior whatsoever, it seems to be working flawlessly.
./file.bat "a;b " c
Output
"a;b"
c
As @jeb mentioned in his comment, enclosing quotes can be trimmed by accessing parameter variable like this
%~1
Upvotes: 7