powershell無法調用Path中Program Files (x86)下的程序?
在Path環境變量加入一個在Program Files (x86)下的路徑后,Get-Command可以正常直接獲取該路徑下的程序,但執行時會因為路徑里的“x86”而報錯。如下所示:
C:> (Get-Command code).Source C:Program Files (x86)Microsoft VS Codeincode.cmd C:> code 警告: Could not find ssh-agent x86 : 無法將“x86”項識別為 cmdlet、函數、腳本文件或可運行程序的名稱。請檢查名稱的拼寫,如果 包括路徑,請確保路徑正確,然后再試一次。 所在位置 行:1 字符: 19 + C:Program Files (x86)Microsoft VS Codeincode.cmd + ~~~ + CategoryInfo: ObjectNotFound: (x86:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundExceptionC:> $env:PATH C:ProgramDataOracleJavajavapath;C:Program Files (x86)InteliCLS Client;C:Program File sInteliCLS Client;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSyste m32WindowsPowerShellv1.0;C:Program Files (x86)IntelIntel(R) Management Engine Component sDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL<愛尬聊_尬聊生活>;C:Program Files (x86) IntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelIntel(R) Management E ngine ComponentsIPT;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program Files IntelWiFiin;C:Program FilesCommon FilesIntelWirelessCommon;C:WINDOWSsystem32;C:WI NDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files odejs;C:Program Files (x86)scalain;C:Program FilesTortoiseGitin;C:WINDOWSsystem32 configsystemprofile.dnxin;C:Program FilesMicrosoft DNXDnvm;C:Program Files (x86)Win dows Kits8.1Windows Performance Toolkit;C:Program FilesMicrosoft SQL Server120ToolsBi nn;C:Program FilesMicrosoft SQL Server130ToolsBinn;C:Program FilesGitcmd;C:UsersD ustarAppDataLocalMicrosoftWindowsApps;C:UsersDustarAppDataRoamingpm;C:Program File s (x86)Microsoft VS Codein C:>
這個問題在cmd里并不會出現。
請問這是什么原因,該怎么解決?
360U3178697387 2022-07-14 13:20
看樣子應該是路徑中有空格,導致解析時出錯,你可以把路徑用引號包起來,避免空格造成歧義。
volker23 2022-07-14 13:38
后來找到原因是把環境變量里的ComSpec改成powershell就會出這個問題