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.
Here is my code so far:
For ($i=0; $i -le 8; $i++) {
start cmd.exe /k node index.js
Start-Sleep -Seconds 60
}
but I keep on getting errors:
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
I have already looked at this answer posted on SuperUser, however, it is not clear to me what I am doing wrong.
The second answer on this stack overflow thread seems to be doing exactly what I am trying to do, but I keep getting the above error.
cmd.exe /k "node index.js"without the start cmdlet.startis an alias in PowerShell forStart-Process. Have you reviewed the information fromhelp Start-Process -Full? What version of PowerShell are you using?$PSVersionTable.PSVersion.ToString()startbefore ithelp Start-Process -FullExample 7 in PowerShell 7.1.2.start cmd.exe /k node index.jswith& cmd /D /K "node index.js"