开发者

Run/invoke windows batch script from sh or bash script

开发者 https://www.devze.com 2023-01-10 04:39 出处:网络
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).

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\"
$COMSP开发者_运维技巧EC /c \"\"batchfile param1 param2\"\"
$COMSPEC /c \"\"batchfile \"param1\" \"param2\"\"\"

But I didn't get any result.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消