views:

37

answers:

1

Hello, 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 to any result..

+1  A: 

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.

Bogdan Maxim