【问题标题】:Executing an exe file in PowerShell in the path variable在路径变量中执行 PowerShell 中的 exe 文件
【发布时间】: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


【解决方案1】:

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

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

DEBUG: CommandDiscovery Information: 0 : 在“E:\My Software\FCIV”中寻找 fciv.ps1

路径是"E:\My Software\FCIV",而它应该是E:\My Software\FCIV
这表明您的路径设置错误,并且在不需要时将此项在您的路径中引用。

这是我运行 iexplore.exe 之后的示例跟踪的摘录:

DEBUG: CommandDiscovery Information: 0 : 寻找 iexplore.exe.* 在 C:\Program Files (x86)\Internet Explorer
调试:CommandSearch 信息:0:WriteLine 找到下一个路径:C:\Program Files (x86)\Internet Explorer\iexplore.exe
调试:CommandDiscovery 信息:0:找到命令:路径(C:\Program Files (x86)\Internet Explorer\iexplore.exe) 是一个应用程序,名称为:iexplore.exe

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

【讨论】:

    猜你喜欢
    • 2019-03-15
    • 1970-01-01
    • 2019-02-11
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多