【问题标题】:How to run windows batch file within shell script?如何在 shell 脚本中运行 windows 批处理文件?
【发布时间】:2018-04-10 04:06:15
【问题描述】:

我不确定如何在 Windows 10 的 shell 脚本中运行 aps.bat 命令。

我尝试了几种不同的方法,但没有成功,我没有更多细节。

请看下面的代码:

#!/bin/bash

output = aps.bat build $PWD;

# do some work...

echo "$output";

基本上,我需要执行aps.bat 命令并将输出存储到变量中。

【问题讨论】:

  • 在 bash 上执行批处理脚本?为什么不直接将其移植到 bash 脚本?

标签: windows shell batch-file windows-subsystem-for-linux


【解决方案1】:
#!/bin/bash

cd /e
output=$(cmd.exe /C  "aps.bat build $PWD")

# do some work...

echo $output

【讨论】:

  • 不幸的是,我得到了相同的结果 :( 'line 3: aps: command not found'。我有上面写的代码的预推送文件,我正在尝试设置 git hook。
  • 尝试输出=$(cmd "/C aps.bat build $PWD")
  • 还是一样 :( 我试过 'output=$(cmd "/e/aps.bat build $PWD")' 因为 .bat 在 'E' 磁盘中,我在里面执行脚本gitbash 使用这个命令'./pre-push'。我不确定这种方法有什么问题?
  • 没什么错,但 gitbash 可能会想另一种方式。尝试 cd 到 /e 然后 start aps.bat ...
  • 找不到 cmd.exe。您需要指定 cmd.exe 的完整安装路径,并且很可能是批处理文件的完整路径。 msdn.microsoft.com/en-us/commandline/wsl/interop
猜你喜欢
  • 1970-01-01
  • 2014-05-04
  • 1970-01-01
  • 2011-06-15
  • 2013-07-30
  • 1970-01-01
  • 1970-01-01
  • 2019-02-23
  • 1970-01-01
相关资源
最近更新 更多