![](/img/trans.png)
[英]Pass value using pipe symbol to a powershell Start-Process command, from cmd window
[英]How to start cmd from within powershell and pass a command to the cmd instance?
I am trying to create an instance of a windows cmd terminal from powershell every minute for a maximum of 8 times and get each cmd instance to run a nodejs script from there.
到目前为止,这是我的代码:
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 的别名
任何 arguments 都必须使用-ArgumentList参数传递。
start "cmd.exe" -ArgumentList "/k node index.js"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.