首页 > 解决方案 > Powershell 命令从位置打开并运行命令

问题描述

学习如何使用 powershell。但我想做的是从特定位置打开命令提示符然后执行命令。

到目前为止,我已经能够设置位置并打开命令提示符但无法运行命令

到目前为止,我已经尝试过了

Set-Location "F:\Projects\GameManagement\server"
start cmd.exe

而且我也尝试过启动过程,但不知道如何设置位置并使用特定程序打开

我试图发送到命令提示符的命令是“nodemon index.js”。有什么建议么?

谢谢

标签: powershell

解决方案


就像cmd.exe,PowerShell 是一个shell,这意味着您可以直接调用控制台应用程序,它会同步执行它们:

Set-Location F:\Projects\GameManagement\server
nodemon index.js

如果nodemon可执行文件也位于 中F:\Projects\GameManagement\server,则必须将最后一行替换
.\nodemon index.jsRobert Cotterman指出的那样,因为与 PowerShell 不同cmd.exe,出于安全原因,PowerShell 不允许仅按名称调用位于当前目录中的可执行文件。

从 PowerShell 内部很少需要调用cmd.exe- 只需使用 PowerShell 本身。


推荐阅读