Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run .bat or .cmd files in bash for windows 10

gcloud.cmd is a Windows command-line script. 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”.

Based on this thread I created a .bashrc file with this entry:

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:

/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:

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?

like image 774
alpha_989 Avatar asked Jun 24 '17 17:06

alpha_989


People also ask

How do I run a batch file in bash?

Batch files can be run by typing "start FILENAME. bat". Alternately, type "wine cmd" to run the Windows-Console in the Linux terminal. When in the native Linux shell, the batch files can be executed by typing "wine cmd.exe /c FILENAME.

Is .cmd and .bat the same?

cmd and . bat file processing is that in a . cmd file the ERRORLEVEL variable changes even on a successful command that is affected by Command Extensions (when Command Extensions are enabled), whereas in . bat files the ERRORLEVEL variable changes only upon errors.


1 Answers

You need to specify the full path to cmd.exe.

I have added the following to my ~/.bash_aliases:

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

with this you can run *.bat files with:

$ cmd ./test.bat
like image 191
Christian Wendt Avatar answered Sep 19 '22 01:09

Christian Wendt