7

I am trying to run glcoud.cmd from the bash shell installed on windows 10. Glcoud is recognized on the cmd prompt, but is not recognized on "bash for windows 10".

based on this thread I have created a .bashrc file with this entry (Can I use gcloud in Git Bash on Windows?):

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

The glcoud.cmd is a windows commandline script. It seems that the path is recognized by bash because when I run gcloud.cmd it returns

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

No command 'cmd' found, did you mean: Command 'cmp' from package 'diffutils' (main) Command 'wmd' from package 'wml' (universe) Command 'dcmd' from package 'devscripts' (main) Command 'mcd' from package 'mtools' (main) Command 'vcmd' from package 'core-network-daemon' (universe) Command 'jcmd' from package 'openjdk-7-jdk' (main) Command 'tcmd' from package 'tcm' (universe) Command 'cm' from package 'config-manager' (universe) Command 'cme' from package 'libconfig-model-perl' (universe) Command 'amd' from package 'am-utils' (universe) Command 'icmd' from package 'renameutils' (universe) Command 'mmd' from package 'mtools' (main) Command 'qcmd' from package 'renameutils' (universe)

How do I run windows commands on bash?

Thanks

paul

alpha_989
  • 4,451
  • 1
  • 33
  • 46
  • 2
    I haven't used bash on windows so don't know this will work, but have you tried `cmd /c gcloud` or similar, so the `gcloud` command would be executed in a `cmd` shell instead of directly in the `bash` shell? – Eric Renouf Jun 24 '17 at 17:52
  • Yeah.. I was just thinking about this. It seems CYGWIN runs .bat files automatically in the native interpreter (https://stackoverflow.com/questions/787522/why-is-it-that-cygwin-can-run-bat-scripts). I have tried the following cmd.exe gcloud.cmd; cmd gcloud.cmd; cmd gcloud; cmd /c gcloud; cmd /c glcoud.cmd – alpha_989 Jun 24 '17 at 18:05
  • none of the above work.. perhaps I should move to cygwin, or install linux in a virtual machine.. – alpha_989 Jun 24 '17 at 18:06
  • 1
    It's hard for people to find information in the comments, and they don't format well, Instead, please [edit](https://stackoverflow.com/posts/44739204/edit) your question to include the updated attempts, and it would probably be helpful to include exact error messages when available instead of a variation on "it didn't work." – Eric Renouf Jun 24 '17 at 18:07
  • ok.. no problem! – alpha_989 Jun 24 '17 at 18:09
  • 2
    Have you tried to use a full path to cmd.exe? as in `/mnt/c/windows/system32/cmd.exe /C gcloud.cmd` You may also want to include /mnt/c/windows/system32/ to your PATH – Michaël Roy Jun 24 '17 at 18:38
  • Thanks.. i just did. Didnt work unfortunately. The only way I found it to work is by getting out of the bash shell using the following in sequence 1. cmd.exe 2. gcloud.cmd 3. exit. however, I was trying to run gcloud.cmd along with some parameters, and pass the output to grep. Grep is installed in the bash shell, and not in the windows command. So I couldnt get it working.. – alpha_989 Jun 24 '17 at 18:43
  • also the PATH maynot be issue here.. because cmd.exe is recognized regardless of which directory I am in, in the bash shell. – alpha_989 Jun 24 '17 at 18:48
  • 2
    Did you read [Bash on Ubuntu on Windows - Bash-Windows Interop](https://msdn.microsoft.com/en-us/commandline/wsl/interop)? –  Jun 24 '17 at 21:11
  • Thanks LotPings. I think I maybe able to work with this.. – alpha_989 Jun 24 '17 at 22:32

2 Answers2

6

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
  • The alias method works, however you will have to adjust the path, because `cmd` will not be able to comprehend `./test.bat`. So you will either have to simply pass `test.bat` without `./` if you are in the directory where your batch file is located, or you need to pass the full path, *i.e.* use a command like this: `cmd 'C:\MyFolder\MySubfolder\test.bat'`. – Koenigsberg Sep 07 '18 at 07:08
2

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? You could split your code in too... Just an idea.

Luke Deven
  • 66
  • 1
  • 8