Azure / azure-cli

Azure Command-Line Interface
MIT License
3.95k stars 2.93k forks source link

Program 'az.cmd' failed to run: The system cannot find the file specifiedAt line:1 char:1 #19202

Closed jiasli closed 3 years ago

jiasli commented 3 years ago

Program 'az.cmd' failed to run: The system cannot find the file specifiedAt line:1 char:1

+ az --version
+ ~~~~~~~~~~~~.
At line:1 char:1
+ az --version
+ ~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

i am facing this error , not getting how to fix it , as i am using windows 10 machine ,powershell 3.10 is installed

Originally posted by @gyalamanch in https://github.com/Azure/azure-cli/issues/9562#issuecomment-897265333

jiasli commented 3 years ago

@gyalamanch, could you share

  1. How did you install Azure CLI? We recommend installing with MSI.
  2. Which version of Azure CLI you are using?
  3. PowerShell 3.10 is very old. Could you try the latest PowerShell 7.1?
  4. What is the output of
    Get-Command az | Format-List
  5. Does it work if you directly invoke:
    & "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" -IBm azure.cli
yonzhan commented 3 years ago

@jiasli for awareness

gyalamanch commented 3 years ago

PS C:\Users\gyalamanch001> Get-Command az | Format-List

Name : az.cmd CommandType : Application Definition : C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd Extension : .cmd Path : C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd FileVersionInfo : File: C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd InternalName: OriginalFilename: FileVersion: FileDescription: Product: ProductVersion: Debug: False Patched: False PreRelease: False PrivateBuild: False SpecialBuild: False Language:

gyalamanch commented 3 years ago

Point 1 : yes its with MSI Point 2 : running with 2.27.1 point 3 : installed powershell 7.1 point 5 : yes even after installing powershell 7.1 it remain same

jiasli commented 3 years ago

This is weird. If you check the content of C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd, it is simply a cmd script which launches Python with Azure CLI:

> Get-Content "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd"
::
:: Microsoft Azure CLI - Windows Installer - Author file components script
:: Copyright (C) Microsoft Corporation. All Rights Reserved.
::

@IF EXIST "%~dp0\..\python.exe" (
  SET AZ_INSTALLER=MSI
  "%~dp0\..\python.exe" -IBm azure.cli %*
) ELSE (
  echo Failed to load python executable.
  exit /b 1
)
  1. Does az work in Command Prompt?
  2. Could you check the content of C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd?
gyalamanch commented 3 years ago

yes it work in command prompt but not in powershell please find the logs from CMD **C:\Users\gyalamanch001>az

Welcome to Azure CLI!

Use az -h to see available commands or go to https://aka.ms/cli.

Telemetry

The Azure CLI collects usage data in order to improve your experience. The data is anonymous and does not include commandline argument values. The data is collected by Microsoft.

You can change your telemetry settings with az configure.

 /\
/  \    _____   _ _  ___ _

/ /\ \ |_ / | | | \'/ \ / ____ \ / /| || | | | / // \\/|_,|| _|

Welcome to the cool new Azure CLI!

Use az --version to display the current version. Here are the base commands:

account             : Manage Azure subscription information.
acr                 : Manage private registries with Azure Container Registries.
ad                  : Manage Azure Active Directory Graph entities needed for Role Based Access
                     Control.
advisor             : Manage Azure Advisor.
afd                 : Manage Azure Front Door.
aks                 : Manage Azure Kubernetes Services.
ams                 : Manage Azure Media Services resources.
apim                : Manage Azure API Management services.
appconfig           : Manage App Configurations.
appservice          : Manage App Service plans.
aro                 : Manage Azure Red Hat OpenShift clusters.
backup              : Manage Azure Backups.
batch               : Manage Azure Batch.
bicep               : Bicep CLI command group.
billing             : Manage Azure Billing.
bot                 : Manage Microsoft Azure Bot Service.
cache               : Commands to manage CLI objects cached using the `--defer` argument.
cdn                 : Manage Azure Content Delivery Networks (CDNs).
cloud               : Manage registered Azure clouds.
cognitiveservices   : Manage Azure Cognitive Services accounts.
config              : Manage Azure CLI configuration.
configure           : Manage Azure CLI configuration. This command is interactive.
consumption         : Manage consumption of Azure resources.
container           : Manage Azure Container Instances.
cosmosdb            : Manage Azure Cosmos DB database accounts.
databoxedge         : Support data box edge device and management.
deployment          : Manage Azure Resource Manager template deployment at subscription scope.
deployment-scripts  : Manage deployment scripts at subscription or resource group scope.
deploymentmanager   : Create and manage rollouts for your service.
disk                : Manage Azure Managed Disks.
disk-access         : Manage disk access resources.
disk-encryption-set : Disk Encryption Set resource.
dla                 : Manage Data Lake Analytics accounts, jobs, and catalogs.
dls                 : Manage Data Lake Store accounts and filesystems.
dms                 : Manage Azure Data Migration Service (DMS) instances.
eventgrid           : Manage Azure Event Grid topics, domains, domain topics, system topics
                     partner topics, event subscriptions, system topic event subscriptions and
                     partner topic event subscriptions.
eventhubs           : Manage Azure Event Hubs namespaces, eventhubs, consumergroups and geo
                     recovery configurations - Alias.
extension           : Manage and update CLI extensions.
feature             : Manage resource provider features.
feedback            : Send feedback to the Azure CLI Team.
find                : I'm an AI robot, my advice is based on our Azure documentation as well as
                     the usage patterns of Azure CLI and Azure ARM users. Using me improves
                     Azure products and documentation.
functionapp         : Manage function apps. To install the Azure Functions Core tools see
                     https://github.com/Azure/azure-functions-core-tools.
group               : Manage resource groups and template deployments.
hdinsight           : Manage HDInsight resources.
identity            : Managed Service Identities.
image               : Manage custom virtual machine images.
interactive         : Start interactive mode. Installs the Interactive extension if not
                     installed already.
iot                 : Manage Internet of Things (IoT) assets.
keyvault            : Manage KeyVault keys, secrets, and certificates.
kusto               : Manage Azure Kusto resources.
lab                 : Manage Azure DevTest Labs.
local-context       : Manage Local Context.
lock                : Manage Azure locks.
login               : Log in to Azure.
logout              : Log out to remove access to Azure subscriptions.
managedapp          : Manage template solutions provided and maintained by Independent Software
                     Vendors (ISVs).
managedservices     : Manage the registration assignments and definitions in Azure.
maps                : Manage Azure Maps.
mariadb             : Manage Azure Database for MariaDB servers.
monitor             : Manage the Azure Monitor Service.
mysql               : Manage Azure Database for MySQL servers.
netappfiles         : Manage Azure NetApp Files (ANF) Resources.
network             : Manage Azure Network resources.
policy              : Manage resource policies.
postgres            : Manage Azure Database for PostgreSQL servers.
ppg                 : Manage Proximity Placement Groups.
provider            : Manage resource providers.
redis               : Manage dedicated Redis caches for your Azure applications.
relay               : Manage Azure Relay Service namespaces, WCF relays, hybrid connections, and
                     rules.
reservations        : Manage Azure Reservations.
resource            : Manage Azure resources.
rest                : Invoke a custom request.
role                : Manage user roles for access control with Azure Active Directory and
                     service principals.
search              : Manage Azure Search services, admin keys and query keys.
security            : Manage your security posture with Azure Security Center.
servicebus          : Manage Azure Service Bus namespaces, queues, topics, subscriptions, rules
                     and geo-disaster recovery configuration alias.
sf                  : Manage and administer Azure Service Fabric clusters.
sig                 : Manage shared image gallery.
signalr             : Manage Azure SignalR Service.
snapshot            : Manage point-in-time copies of managed disks, native blobs, or other
                     snapshots.
sql                 : Manage Azure SQL Databases and Data Warehouses.
sshkey              : Manage ssh public key with vm.
staticwebapp        : Manage static apps.
storage             : Manage Azure Cloud Storage resources.
synapse             : Manage and operate Synapse Workspace, Spark Pool, SQL Pool.
tag                 : Tag Management on a resource.
term                : Manage marketplace agreement with marketplaceordering.
ts                  : Manage template specs at subscription or resource group scope.
upgrade             : Upgrade Azure CLI and extensions.
version             : Show the versions of Azure CLI modules and extensions in JSON format by
                     default or format configured by --output.
vm                  : Manage Linux or Windows virtual machines.
vmss                : Manage groupings of virtual machines in an Azure Virtual Machine Scale Set
                     (VMSS).
webapp              : Manage web apps.

C:\Users\gyalamanch001>*

Please find the logs from powershell PS C:\Users\gyalamanch001> az login ResourceUnavailable: Program 'az.cmd' failed to run: The system cannot find the file specified.At line:1 char:1

jiasli commented 3 years ago

I found these posts on internet:

The error doesn't seem to come from az.cmd, but from some misconfiguration of CMD itself. Could you open Registry Editor by running regedit and check the value of

HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun

If there is any command, please remove it to see if the issue is solved.

gyalamanch commented 3 years ago

i do not see that in the path image

jiasli commented 3 years ago

You are checking HKEY_LOCAL_MACHINE. How about HKEY_CURRENT_USER?

gyalamanch commented 3 years ago

both

jiasli commented 3 years ago

I don't really know what is going wrong with the CMD on you system. 😥 Does it happen on another computer? Or could you create another Windows user to isolate the problem?

gyalamanch commented 3 years ago

reimaged the laptop to fix the issue

jiasli commented 3 years ago

@gyalamanch, I am glad to know the issue is fixed. It is very likely to be caused by some other installed software or anti-virus software that corrupts the PowerShell or CMD environment.