powershell - Powershell 命令从位置打开并运行命令
问题描述
学习如何使用 powershell。但我想做的是从特定位置打开命令提示符然后执行命令。
到目前为止,我已经能够设置位置并打开命令提示符但无法运行命令
到目前为止,我已经尝试过了
Set-Location "F:\Projects\GameManagement\server"
start cmd.exe
而且我也尝试过启动过程,但不知道如何设置位置并使用特定程序打开
我试图发送到命令提示符的命令是“nodemon index.js”。有什么建议么?
谢谢
解决方案
就像cmd.exe
,PowerShell 是一个shell,这意味着您可以直接调用控制台应用程序,它会同步执行它们:
Set-Location F:\Projects\GameManagement\server
nodemon index.js
如果nodemon
可执行文件也位于 中F:\Projects\GameManagement\server
,则必须将最后一行替换
.\nodemon index.js
为Robert Cotterman指出的那样,因为与 PowerShell 不同cmd.exe
,出于安全原因,PowerShell 不允许仅按名称调用位于当前目录中的可执行文件。
从 PowerShell 内部很少需要调用cmd.exe
- 只需使用 PowerShell 本身。
推荐阅读
- python - 在函数中使用字符串作为变量(Python)
- if-statement - Logstash 条件检查字段中的 nil/null 值
- php - 如何在 PHP 中使用 Youtube API 获取 youtube 评论回复?
- maven - Maven 故障安全没有抱怨指定了不存在的配置文件
- python - 确认 TF2 在训练时正在使用我的 GPU
- jenkins - 更改变量会删除 Jenkins groovy-script 中的其他变量
- pandas - Pandas Dataframe:如何获取单元格而不是值
- android - 如何在 TextInput 中禁用 keyboardAvoidingView 行为
- java - 如何避免 IntelliJ 中可嵌入类的验证错误“无法解析列‘xy’”?
- apify - 从 sitemap.xml 抓取每个链接