PowerShell run two processes in parallel and display combined stdout in the terminal

Question:

I’d like to get some help putting together a PowerShell script that starts two processes (in my case two servers that monitor file changes and report, writing stuff to stdout continuously) and mixes their respective outputs into one terminal window?

I am not interested in writing into files. I want to monitor the two intertwined output streams in the same PowerShell terminal window. I know that at points there will be mix of “unfinished” chunks from one process intertwined with the same from the other etc., but I don’t mind that.

Image these two scripts as inputs:

left.ps1

right.ps1

The desired outputs is:

It would be nice having the process die when both of the started processes die and also to kill the started processes upon ^C, but neither is required.

I am using Windows so a Windows-only answer is fine. I do not want to use tmux or screen if possible.
(I’m not interested in Cygwin and also I do not want two columns but a mix of stdouts.)
A WSL solution would also be interesting.

Answer:

You can use Start-Process cmdlet with -NoNewWindow switch to start new independent console application attached to the same console window:


If you want to start PowerShell script this way, then you need to start new PowerShell process for it:

Source:

PowerShell run two processes in parallel and display combined stdout in the terminal by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply