PowerShell问题 - 我必须输入./来运行bat文件

时间:2012-01-28 16:35:53

标签: powershell powershell-v2.0

我刚刚安装了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 文件时,有没有办法避免输入 ./

3 个答案:

答案 0 :(得分:5)

您尝试运行批处理文件的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对此进行了一些讨论。

答案 1 :(得分:2)

我没有PowerShell试试这个,但是如果你设置路径包含当前文件夹,这应该有效:

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

答案 2 :(得分:1)

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

相关问题