【发布时间】:2016-06-03 16:33:56
【问题描述】:
我在一个文件夹中有一个 exe 文件 fciv.exe,我已将它添加到我的路径变量中。 我使用
检查了它$env:Path
但如果我只是指定命令的名称,
fciv -h
powershell 显示 command not found 异常。
在 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 仍然可以工作,但是 powershell 不能, 我不明白为什么,但我很高兴我至少找到了解决问题的方法。
【问题讨论】:
-
显示
Trace-Command Command* {fciv -h} -PSHost命令的输出。 -
伙计,这个
Trace-Command的东西是丑陋的冗长的! -
是的,我已经添加了相关的输出行,它在正确的文件夹中查找但似乎找不到文件,我猜扩展名有问题。
-
你确定你有
E:\My Software\FCIV\fciv.exe而不是fciv.exe.exe什么的吗?gi 'E:\My Software\FCIV\fciv.exe'向你展示了什么? -
是的,已知的文件扩展名被隐藏,文件资源管理器显示的名称只是 fciv 和 gi 确实给出了它能够找到文件的预期输出。
标签: powershell cmd executable