【问题标题】:How do you remove the PowerShell requirement that scripts and executables be preceded by ".\"?如何删除脚本和可执行文件前面带有“.\”的 PowerShell 要求?
【发布时间】:2020-04-06 03:31:04
【问题描述】:

如何取消 PowerShell 要求脚本和可执行文件以“.\”开头的要求?

输入“a.exe”而不是“.\a.exe”时显示的 PowerShell 警告消息:

The command a.exe was not found, but does exist in the current location. Windows PowerShell doesn't load commands from the current location by default. If you trust this command, instead type ".\a.exe".

【问题讨论】:

    标签: powershell


    【解决方案1】:

    这是一项安全功能,因此您可以运行您认为正在运行的脚本。这就是为什么不像 cmd,你在 PATH 中没有 .(当前目录),你必须做 .\my.exe 等等。

    如果您不想这样做并破坏此预防措施,请将. 添加到您的PATH:

    $env:PATH =$env:PATH+";."
    

    【讨论】:

    • 不幸的是,这个技巧在最新版本中停止工作(使用 PowerShell 7.1.3 测试)。一般错误消息后面是:Suggestion [3,General]: The command mycommand was not found, but does exist in the current location. PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\mycommand". See "get-help about_Command_Precedence" for more details.
    • @IgorAkkerman,它适用于我在 Powershell 7.2.0 中。想再试一次——也许这是修复后的回归?
    • @PatrickSzalapski 感谢您的提示,它在 7.2.1 中也适用于我。
    【解决方案2】:

    在您的path(环境变量)中添加您通常放置scriptexe 文件的路径。

    【讨论】:

      【解决方案3】:

      重命名脚本文件,使其以“.”开头。

      https://github.com/PowerShell/PowerShell/issues/9468

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-24
        • 2019-01-25
        • 1970-01-01
        相关资源
        最近更新 更多