在路径变量中的 PowerShell 中执行一个 exe 文件

Executing an exe file in PowerShell in the path variable

我在已添加到我的路径变量的文件夹中有一个 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 却不行, 我不明白为什么,但我很高兴我至少找到了解决问题的方法。

注意:您已经用答案更新了问题,但很高兴发布实际答案。

在您的调试跟踪中,您得到如下行:

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

请注意,路径未被引用,它找到了可执行文件。