20

I need to run two commands which never terminate. What I normally do is to

  • start a cmd terminal and type in the first command
  • start another cmd terminal and type in the second command

I then have my two processes running in parallel.

I now would like to automate this by having one "startup" file which would lauch the two terminals above. It can be cmd or PowerShell based.

Note 1: I tried to use cmd with /k or /c but this does not spawn a new terminal. Trying something like cmd /c cmd ended up with Internal Error output in the shell.

Note 2: PowerShell has Background Jobs. The problem is that I want to have two separate shells I can monitor the output on (and eventually close the running process with Ctrl-C.

Is there a way to achieve this in one file?

3 Answers 3

24

Create a batch file:

start cmd.exe /c <first command>
start cmd.exe /c <second command>

Run the batch file and it will open the two cmd windows and the batch file will exit.

4
  • 1
    What does the "/c" flag stand for? Commented Apr 2, 2019 at 11:34
  • 2
    @BrunoBieri /c tells cmd to run the command then exit. As opposed to /k that tells cmd to run the command and remain open - basically sit at the command prompt. If you need help with command line switches you can use cmd /?. Commented Apr 2, 2019 at 14:19
  • What if the commands I want to pass to cmd are batch files themselves ?
    – Charles
    Commented Apr 17, 2023 at 15:02
  • @Charles just specify the batch file name in place of the command name. Same behavior. Commented Apr 18, 2023 at 16:38
0

I believe 'start cmd /c dir' is what you're looking for.
edit: Well, /k for short example like dir, but 'start' is the magic word you need.

0

emphasized textQuote from Ren "I believe 'start cmd /c dir' is what you're looking for."

I personally think that 'start cmd /c dir /s' would be even better

3
  • Or 'start cmd /c dir /s /p' would be Even Better than both of those heh Commented Mar 13 at 11:36
  • SORRY I JUST REALIZED THIS OLD AF ANYWAYS LOL!! WHAT AM I EVEN DOING ON THE SUPERFICIAL WEB NE WHO INSTEAD OF THE DW??? I'VE LOST IT! Commented Mar 13 at 11:41
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 13 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .