0

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.

5
  • try cmd.exe /k "node index.js" without the start cmdlet. Commented Apr 9, 2021 at 22:28
  • start is an alias in PowerShell for Start-Process. Have you reviewed the information from help Start-Process -Full? What version of PowerShell are you using? $PSVersionTable.PSVersion.ToString() Commented Apr 9, 2021 at 23:07
  • 1
    @AbrahamZinala Unfortunately that doesnt work, because it does not create a new instance of cmd in a new window like it would if it had the start before it Commented Apr 9, 2021 at 23:15
  • See especially help Start-Process -Full Example 7 in PowerShell 7.1.2. Commented Apr 9, 2021 at 23:15
  • Similar to Abrahams comment, I would probably try replacing start cmd.exe /k node index.js with & cmd /D /K "node index.js" Commented Apr 10, 2021 at 0:59

1 Answer 1

2

Start is an alias for the Start-Process cmdlet as mentioned by @lit

Any arguments have to passed on with the -ArgumentList parameter.

start "cmd.exe"  -ArgumentList "/k node index.js"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.