3

Sometimes I have a problem with running various commands (I'm using Git Bash, if that matters). For example, when I try to execute:

az container exec --resource-group My-RG --name influxdb-container --exec-command "/bin/bash"

The command above should normally "SSH" me into the Azure Container Instance. However, instead, I'm getting:

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

I found a lot of posts on SO with such error, however, the issue in those posts was about invoking commands without proper quoting of "C:\Program Files". In my case, however, there is no "Program Files" anywhere, so I have a hard time figuring out what is wrong.

az command is recognized by the shell, when I invoke it alone, I'm getting proper response from Azure CLI.

I am also getting a similar error when running docker commands sometimes. Unfortunately, right now I do not know which command exactly would cause that.

This issue happens only on my Windows machine. When I run the command from Linux or macOS, it just works.

Screenshot of the error: enter image description here

And the proof that az works:

enter image description here

mnj
  • 2,539
  • 3
  • 29
  • 58
  • It probably is going to be the quoting error, but it'll be taking the unquoted string from either your environment variables or the registry I'd guess, and not handling it correctly for whatever reason. I don't have any good ideas where to start looking though. Is there any obvious config that azure-cli uses you can check for instances of C:\Program Files\ ? – Rup May 14 '20 at 06:58
  • @Rup I looked through `%USERPROFILE%\.azure` and didn't see anything like it. – mnj May 14 '20 at 09:29
  • Is `/bin/bash` a script file? (.cmd or .bat) – avery_larry May 14 '20 at 14:14
  • @avery_larry "/bin/bash" is a program that I want to run inside of my Azure Container instance – mnj May 15 '20 at 16:09
  • Forgive me as I'm not familiar with Azure CLI. However, I'm trying to find out if /bin/bash is a physical file you have access to. If it is, then I want to know if it is bash.cmd or bash.bat or bash.pl or bash.exe or bash.com or whatever. Or you can just open the file with notepad and look in it to see if there is any unquoted "c:\program files" lines in it anywhere. – avery_larry May 22 '20 at 14:44
  • Or for that matter az may well be a script file az.bat or az.cmd that you can take a look at. – avery_larry May 22 '20 at 14:45
  • The error seems caused by a leading `/` within your command arguments. In your example above, it's `--exec-command "/bin/bash"`. – sschmeck May 26 '20 at 09:24

2 Answers2

1

There are some things different between Linux and Windows for Azure CLI. But still, there is some configuration that is the same. You can also set the environment variable PATH the same as in Linux.

In Linux, the az command is in the path /usr/bin/, and this path is also set the environment variable PATH. Then the az command can be recognized by the shell. So the same in Windows, you can also append the path of the Azure CLI in the environment variable PATH. The screenshot shows the configuration on my side:

enter image description here

Then the az command can also be recognized by the CMD:

enter image description here

But you can also use WSL in the Windows and the same experience of the Azure CLI as in Linux.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • I read the question as that az ais already in the path but the problem is running `az container exec` spawns another process using a broken path. – Rup May 15 '20 at 08:20
  • @Rup I don't think so. Why run the Azure CLI inside the Windows container? And he also knows the `az container exec` command only supports the single command. – Charles Xu May 15 '20 at 08:26
  • Yep, "az" is in the path and I am able to run it successfully. Like @Rup mentioned, I have issue with running the specific command that I pasted in my question. – mnj May 15 '20 at 16:10
  • @CharlesXu I don't use "Windows containers". I'm running the `az` command from wishing normal Windows 10 installation. – mnj May 15 '20 at 16:11
  • @Loreno Of course, that is what I said in the answer. Rup said in the container, not me. So you just need to follow the answer. – Charles Xu May 18 '20 at 01:21
  • @Loreno Any more questions? Do you solve the problem? I didn't see any updates and you also didn't accept it. – Charles Xu May 19 '20 at 03:15
  • @CharlesXu I have it setup same as you have. I was able to run "az" command since the beginning. The issue is with the "az container exec --resource-group My-RG --name influxdb-container --exec-command "/bin/bash"" command only. – mnj May 19 '20 at 07:56
  • @Loreno Do you mean only the command `az container exec` got the error in the windows cmd, others are OK? Do you set something else or change some configuration of the cmd? – Charles Xu May 19 '20 at 08:12
  • @CharlesXu yes, exactly that. Nope, no custom configs. – mnj May 19 '20 at 13:07
  • @Loreno Can you share the screenshot of the error in the question? It's more clear to me. – Charles Xu May 20 '20 at 01:17
  • @CharlesXu Added to my question. – mnj May 20 '20 at 13:51
  • BTW, just found out that the command works from CMD. Only from Bash it fails – mnj May 20 '20 at 13:52
  • @Loreno Maybe you can try to put the command `"/bin/bash -c '/bin/bash'"` append the parameter `exec-command`. I don't know why it happens on your site. Everything is ok on my side. – Charles Xu May 21 '20 at 06:37
0

I had a very similar issue but with AWS sam.cmd command. Ended up solving it by editing my environment variables -> editing the "Path" system variable and using the "short path" to this command (which doesn't have any spaces) instead of the "long path". (A nice utility called Path Copy Copy helped with doing this.)

Changed from: C:\Program Files\Amazon\AWSSAMCLI\bin to: C:\PROGRA~1\Amazon\AWSSAM~1\bin

Would suspect doing something similar for the az command would have solved your issue. Suspect it may be something to do with Git Bash automatically putting quotes around the whole command when the path to the executable has whitespace in it.

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208