Azure-cli: Error "'C:\Program' is not recognized as an internal or external command" when running az role assignment create cmd

Created on 25 Apr 2019  路  18Comments  路  Source: Azure/azure-cli

Describe the bug
Running the 1st bash script in doc Authenticate with Azure Container Registry from Azure Kubernetes Service, last cmd generates error

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

Other az-cli cmds work in the same environment so far.

Environment summary
Windows 10, git bash in mingw64, alias az=az.cmd

$ az --version
azure-cli                         2.0.62 *

acr                                2.2.4 *
acs                               2.3.21 *
advisor                            2.0.0
ams                                0.4.4 *
appservice                        0.2.17 *
backup                             1.2.3 *
batch                              4.0.0
batchai                            0.4.8
billing                            0.2.1
botservice                        0.1.10
cdn                                0.2.2 *
cloud                              2.1.1
cognitiveservices                  0.2.5
command-modules-nspkg               2.0.2
configure                         2.0.21 *
consumption                        0.4.2
container                         0.3.16
core                              2.0.62 *
cosmosdb                           0.2.9 *
dla                                0.2.5
dls                                0.1.8 *
dms                                0.1.3
eventgrid                          0.2.2 *
eventhubs                          0.3.4
extension                          0.2.5
feedback                           2.2.0 *
find                               0.3.2
hdinsight                          0.3.3
interactive                        0.4.3
iot                                0.3.7 *
iotcentral                         0.1.6
keyvault                          2.2.14
kusto                              0.2.2
lab                                0.1.6 *
maps                               0.3.4
monitor                           0.2.12 *
network                            2.3.6 *
nspkg                              3.0.3
policyinsights                     0.1.2
privatedns                         1.0.0
profile                            2.1.5
rdbms                              0.3.9 *
redis                              0.4.2
relay                              0.1.4
reservations                       0.4.2
resource                          2.1.13 *
role                               2.5.0 *
search                             0.1.1
security                           0.1.1
servicebus                         0.3.4
servicefabric                     0.1.16 *
signalr                            1.0.0
sql                                2.2.1 *
sqlvm                              0.1.1
storage                            2.4.0 *
telemetry                          1.0.2
vm                                2.2.18 *
OKR3.4 Candidate Shell

Most helpful comment

This is a bug in Git Bash itself, irrelevant to Azure CLI.

To reproduce, create a cmd file with spaces in the path, such as D:\path with space\test.cmd:

echo Hello World

Directly invoking this file works:

$ test.cmd

C:\Users\xxx>echo Hello World
Hello World

$ "D:\path with space\test.cmd"

C:\Users\xxx>echo Hello World
Hello World

But it fails when a parameter with space is provided:

$ test.cmd "a b"
'D:\path' is not recognized as an internal or external command,
operable program or batch file.

$ "D:\path with space\test.cmd" "a b"
'D:\path' is not recognized as an internal or external command,
operable program or batch file.

All 18 comments

Just to be clear, are you referring to the az role assignment create?

yes

Can you run with --debug and include the first line of output (which says "Command arguments":")

added --debug to az role assignment create --assignee $CLIENT_ID --role acrpull --scope $ACR_ID. Regardless of the position the option is placed, output is the same as shown at top without adding any more details.

From your initial report, it seems like you have a path containing spaces that needs to be quoted. If you didn't supply a path, then it appears that git bash itself is appending some kind of unquoted path, in which case there is nothing the CLI can do because your error is occurring before the input ever reaches the CLI. The recommendation then would be to use a different shell. Because of certain anomalous behavior with git bash, we do not recommend using it with Azure CLI.

Does that make this a duplicate of https://github.com/Azure/azure-cli/issues/8560?

I'm not sure it's really a duplicate, though they are related by shell.

This happens anytime you input a param within " (double quote) character with space in between using bash.

e.g. Command like this will fail..

az.cmd tag create -n "temporary tag"

Another related issue reported on our extension - https://github.com/Azure/azure-devops-cli-extension/issues/606

You will not get debug logs for this since the execution it self fails. Check the related issue above for more details and yes this does look like a dupe of #8560.

@atbagga , not true in my case since the cmd I executed doesn't contain strings with spaces - az role assignment create --assignee $CLIENT_ID --role acrpull --scope $ACR_ID. It could be because a child cmd contains space but that's beyond my call. Also, az is installed under c:\program files and the install program doesn't offer the option to install elsewhere.

FWIW: had a similar issue on msys2, turned out that one of the bash vars I was using had a trailing \r which caused the weird error message about C:\Program is not recognized ...

I solved it using something like VAR=$(echo "$VAR" | tr -d "\n\r")

add to S170

add to S172

I'm hitting this in GitBASH using --query

$ az account list -o table --query "[*].{subscriptionId: id}"
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

I'm having the problem from Git Bash for Windows with:

az group export --name aksworkshop --resource-ids "/subscriptions/XXXXXX-XXXXXX/resourceGroups/aksworkshop/providers/Microsoft.DBforMySQL/servers/mysqlxxxxxx"

I can run the command without the --resource-ids parameter. I've tried passing the resource-id without quotes, with single quotes, and with back slashes in place of the forward slash. Nothing seems to work.

The command runs fine in Azure shell.

I'm having the problem from Git Bash for Windows with:

az group export --name aksworkshop --resource-ids "/subscriptions/XXXXXX-XXXXXX/resourceGroups/aksworkshop/providers/Microsoft.DBforMySQL/servers/mysqlxxxxxx"

I can run the command without the --resource-ids parameter. I've tried passing the resource-id without quotes, with single quotes, and with back slashes in place of the forward slash. Nothing seems to work.

The command runs fine in Azure shell.

@snpdev, your issue is caused by Git Bash's path conversion. Please see Use Azure CLI with Git Bash for detailed explanations and solutions.

This is a bug in Git Bash itself, irrelevant to Azure CLI.

To reproduce, create a cmd file with spaces in the path, such as D:\path with space\test.cmd:

echo Hello World

Directly invoking this file works:

$ test.cmd

C:\Users\xxx>echo Hello World
Hello World

$ "D:\path with space\test.cmd"

C:\Users\xxx>echo Hello World
Hello World

But it fails when a parameter with space is provided:

$ test.cmd "a b"
'D:\path' is not recognized as an internal or external command,
operable program or batch file.

$ "D:\path with space\test.cmd" "a b"
'D:\path' is not recognized as an internal or external command,
operable program or batch file.

Why is this failing on GitBASH? I used the MSI installer

$ MSYS_NO_PATHCONV=1 az account list-locations --query "[].{DisplayName:displayName, Name:name}" -o table
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Why is this failing on GitBASH? I used the MSI installer

$ MSYS_NO_PATHCONV=1 az account list-locations --query "[].{DisplayName:displayName, Name:name}" -o table
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

This is a bug of Git Bash and I am afraid I can't provide more info on "why". Git Bash is not officially supported by Azure CLI.

Was this page helpful?
0 / 5 - 0 ratings