powershell - 如何从 powershell 中启动 cmd 并将命令传递给 cmd 实例?
问题描述
我正在尝试每分钟从 powershell 创建一个 windows cmd 终端的实例,最多 8 次,并让每个 cmd 实例从那里运行一个 nodejs 脚本。
到目前为止,这是我的代码:
For ($i=0; $i -le 8; $i++) {
start cmd.exe /k node index.js
Start-Sleep -Seconds 60
}
但我不断收到错误:
Start-Process : A positional parameter cannot be found that accepts argument 'node'.
At C:\Users\user\Documents\x\x\build\src\start.ps1:2 char:5
+ start cmd.exe /k node index.js
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand
我已经查看了在 SuperUser 上发布的这个答案,但是,我不清楚我做错了什么。
这个堆栈溢出线程的第二个答案似乎正在做我想做的事情,但我不断收到上述错误。
解决方案
Start是@lit 提到的Start-Process cmdlet 的别名
任何参数都必须使用-ArgumentList参数传递。
start "cmd.exe" -ArgumentList "/k node index.js"
推荐阅读
- npm - Gitlab-ci 私有包安装失败
- terraform - Terraform - 云从列表中运行多个环境变量
- java - 覆盖继承的 Bean 的名称
- python-3.x - 我正在尝试对列进行屏蔽,并且需要根据相应列中单个单元格中的字符数进行屏蔽
- node.js - 如何使用 findOne 查询 mongodb 并排除数组中的一些嵌套字段
- node.js - 有什么方法可以更新表格行数据并发送到后端 API 吗?
- python - 如何将包含列表的数据框转换为 3D 数组
- laravel - 为什么分页请求在地图中添加计算会引发错误?
- google-ad-manager - Prebid.js 不适用于新的谷歌隐私和消息传递(gdpr 弹出窗口)
- java - 从 Infinispan 8 升级到 12