【问题标题】:PowerShell issue - I have to type ./ to run bat filePowerShell 问题 - 我必须输入 ./ 才能运行 bat 文件
【发布时间】:2012-01-28 16:35:52
【问题描述】:

我刚刚安装了 PHP & Yii 框架。它工作正常,我用 CMD 玩过。但过了一会儿,我切换到 PowerShell ISE。我导航到 Yii 文件夹:

cd C:\dev\yii-1.1.9.r3527\framework

我发出命令:

yiic.bat

我得到一个错误:

PS C:\dev\yii-1.1.9.r3527\framework> yiic.bat
The term 'yiic.bat' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:9
+ yiic.bat <<<< 
    + CategoryInfo          : ObjectNotFound: (yiic.bat:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

但是当我输入时:

./yiic.bat

进入 PowerShell 窗口,它工作正常。

有没有办法避免每次运行 bat 文件时都输入 ./

【问题讨论】:

    标签: powershell powershell-2.0


    【解决方案1】:

    这是一个老问题,但我偶然发现它正在寻找其他东西。 Powershell 要求您输入 .\ 以按照设计在当前运行命令。 https://blogs.technet.microsoft.com/csps/2010/06/06/introduction-to-windows-powershell-scripting/

    【讨论】:

      【解决方案2】:

      您尝试从中运行批处理文件的framework 目录显然不在您的路径中。当您在 shell 中键入 yiic.bat 时,它会在您的 path 环境变量中包含的目录列表中查找该文件。有关如何在 powershell 中设置 path 的信息,请参阅 this question

      例如,如果您希望能够运行C:\dev\yii-1.1.9.r3527\framework 目录中的批处理文件,则可以说$env:Path = $env:Path + ";C:\dev\yii-1.1.9.r3527\framework"

      或者,正如 mloskot 所说,您可以将当前目录添加到您的路径中,尽管这可能会带来轻微的安全风险。参见例如this question 对此进行一些讨论。

      【讨论】:

        【解决方案3】:

        我没有 PowerShell 来试试这个,但如果你将路径设置为包含当前文件夹,这应该可以:

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

        【讨论】:

        • 或者只是$Env:Path += ';.'
        • 简单又好听
        猜你喜欢
        • 1970-01-01
        • 2015-06-29
        • 1970-01-01
        • 1970-01-01
        • 2014-10-06
        • 2020-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多