0

Trying to start a new process in a separate command prompt on Windows 10, but can't find how to execute commands in opened prompt. With Powershell, I could use -Command:

Start-Process PowerShell "-Command tasklist"

But how to do that in Command Prompt window? This, obviously, doesnt work:

Start-Process cmd '-Command tasklist'

3
  • 1
    Have you tried cmd /? for help? The option you're looking for is /C Commented Aug 10, 2021 at 17:24
  • Oh, didint knew about this /? thing. Thanks. Will keep this open in case of an interest to provide a detailed answer Commented Aug 10, 2021 at 17:29
  • I'm a bit busy right now so I won't leave a proper answer. Feel free to self-answer though. Commented Aug 10, 2021 at 17:32

1 Answer 1

1

You're using the PowerShell arguments for cmd.exe. cmd /? will give you the usage, but what you want is cmd /c COMMAND [ARGUMENTS]:

Start-Process cmd "/c ping -n 4 google.com"

@Jeff Zeitlin was kind enough to provide a link to the SS64 CMD usage.


Worth mentioning, you don't need to use Start-Process when running external commands unless:

  • You are running a GUI application and wait to use the -Wait parameter to wait until the program exits
  • You want to run something in a different process asynchronously and check the result later
    • In this case don't forget to use -PassThru and assign the process to a variable, so you can check the result when ready
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, great answer. I am running this from Node application.

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.