我在添加到我的路径变量的文件夹中有一个exe文件fciv.exe。
我用
$env:Path
但是,如果我只指定命令的名称,
fciv -h
powershell显示命令未找到异常。
该命令在cmd命令提示符下起作用。
我已将执行策略设置为无限制
为了使它在Powershell中工作,我还有什么需要做的吗?
编辑
输出的相关行
Trace-Command Command* {fciv -h} -PSHost
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.ps1 in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.psm1 in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.psd1 in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.COM in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.EXE in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.BAT in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.CMD in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.VBS in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.VBE in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.JS in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.JSE in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.WSF in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.WSH in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.MSC in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.CPL in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandDiscovery Information: 0 : Looking for fciv in "E:\My Software\FCIV"
DEBUG: CommandSearch Information: 0 : WriteLine Current directory results are invalid
DEBUG: CommandSearch Information: 0 : WriteLine Current patterns exhausted in current directory: "E:\My Software\FCIV"
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.ps1 in E:\My Software\AVG\Av
请注意,“E:\ My Software \ FCIV”是fciv可执行文件所在的目录。
编辑2
查看命令跟踪并发现它在正确的文件夹中寻找fciv.EXE,但跳过正确的地方,我认为扩展.EXE的大写是问题所在,因此我尝试将.exe添加到PATHEXT变量中
现在,它在正确的文件夹中查找fciv.exe,但仍会跳过它,并说它已用尽当前目录中的当前模式。
编辑3
我已经弄清楚了,看来在我的 PATH 环境变量中
"E:\My Software\FCIV"
出现在双引号中,没有其他目录。
尽管有此功能,但命令提示符 cmd 仍然可以工作,
我不明白为什么,但我很高兴至少找到了解决问题的方法。
最佳答案
注意:您已经用答案更新了您的问题,但是发布实际答案很好。
在调试跟踪中,您将获得如下所示的代码行:
DEBUG: CommandDiscovery Information: 0 : Looking for fciv.ps1 in "E:\My Software\FCIV"
路径应为
"E:\My Software\FCIV"
,但应为E:\My Software\FCIV
。这表明您的路径设置不正确,并且在不需要时将其引用在您的路径中。
这是我运行iexplore.exe之后的示例跟踪的摘录:
DEBUG: CommandDiscovery Information: 0 : Looking for iexplore.exe.* in C:\Program Files (x86)\Internet Explorer
DEBUG: CommandSearch Information: 0 : WriteLine Next path found: C:\Program Files (x86)\Internet Explorer\iexplore.exe
DEBUG: CommandDiscovery Information: 0 : Command Found: path (C:\Program Files (x86)\Internet Explorer\iexplore.exe) is an application with name: iexplore.exe
请注意,没有引用路径,而是找到了可执行文件。
关于powershell - 在PowerShell中的路径变量中执行exe文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37619437/