简体   繁体   English

如何从 Bash for Windows 10 运行 .bat 或 .cmd 文件

[英]how to run .bat or .cmd files from Bash for Windows 10

gcloud.cmd is a Windows command-line script. gcloud.cmd是一个 Windows 命令行脚本。 I am trying to run it from the Bash shell installed on Windows 10. It is recognized by the CMD prompt, but not by “Bash for Windows 10”.我正在尝试从安装在 Windows 10 上的 Bash shell 运行它。它可以被 CMD 提示识别,但不能被“Bash for Windows 10”识别。

Based on this thread I created a .bashrc file with this entry:基于这个线程,我用这个条目创建了一个.bashrc文件:

PATH=$PATH:/mnt/c/Users/username/AppData/Local/Google/Cloud SDK/google-cloud-sdk/bin

It seems that Bash now finds the file because when I run gcloud.cmd it shows:似乎 Bash 现在找到了该文件,因为当我运行gcloud.cmd时它显示:

/mnt/c/Users/***/AppData/Local/Google/Cloud SDK/google-cloud-sdk/bin/gcloud.cmd: line 1: @echo: command not found
/mnt/c/Users/***/AppData/Local/Google/Cloud SDK/google-cloud-sdk/bin/gcloud.cmd: line 2: rem: command not found
/mnt/c/Users/***/AppData/Local/Google/Cloud SDK/google-cloud-sdk/bin/gcloud.cmd: line 7: syntax error near unexpected token `newline'
/mnt/c/Users/***/AppData/Local/Google/Cloud SDK/google-cloud-sdk/bin/gcloud.cmd: line 7: `rem <cloud-sdk-cmd-preamble>'

I also tried the following commands because Cygwin seems to recognize .bat files automatically:我还尝试了以下命令,因为 Cygwin 似乎可以自动识别.bat文件:

cmd.exe gcloud.cmd
cmd gcloud.cmd 
cmd gcloud
cmd /c gcloud
cmd /c glcoud.cmd

All of the above commands show:上述所有命令显示:

No command 'cmd' found, did you mean: (…)

How do I run Windows Batch commands from Bash?如何从 Bash 运行 Windows Batch 命令?

You need to specify the full path to cmd.exe.您需要指定 cmd.exe 的完整路径。

I have added the following to my ~/.bash_aliases:我在 ~/.bash_aliases 中添加了以下内容:

alias cmd='/mnt/c/Windows/System32/cmd.exe /c'

with this you can run *.bat files with:有了这个,你可以运行 *.bat 文件:

$ cmd ./test.bat

Sorry to post this as an answer but I cannot yet comment.很抱歉将此作为答案发布,但我还不能发表评论。 I was thinking that maybe you could have a batch file that calls bash scripts, then once they exit, it starts to bat files, then starts more bash scripts?我在想也许你可以有一个调用 bash 脚本的批处理文件,然后一旦它们退出,它就开始 bat 文件,然后启动更多的 bash 脚本? You could split your code in too... Just an idea.您也可以将代码拆分...只是一个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM