我在我添加到路径变量的文件夹中有一个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 能够工作尽管如此,但PowerShell不是, 我不知道为什么,但我很高兴我至少知道如何解决问题。
答案 0 :(得分:1)
注意:您已经用答案更新了您的问题,但发布实际答案真的很棒。
在调试跟踪中,您将获得如下所示的行:
DEBUG:CommandDiscovery信息:0:在" E:\ My Software \ FCIV"
中寻找fciv.ps1
路径为"E:\My Software\FCIV"
,应为E:\My Software\FCIV
这表示您的路径设置不正确,并且当您不需要时,会在您的路径中引用此项目。
以下是我运行iexplore.exe的示例跟踪的摘录:
DEBUG:CommandDiscovery信息:0:寻找iexplore.exe。* in C:\ Program Files(x86)\ Internet Explorer
的应用程序
DEBUG:CommandSearch 信息:0:WriteLine找到下一个路径:C:\ Program Files (x86)\ Internet Explorer \ iexplore.exe
调试:CommandDiscovery 信息:0:找到命令:路径(C:\ Program Files(x86)\ Internet Explorer \ iexplore.exe)是一个名称为:iexplore.exe
请注意,路径未引用,并且找到了可执行文件。