s952163
s952163

Reputation: 6324

Background Job in powershell while writing to STDOUT/Console

I have GUI.exe application that sometimes prints messages back to the console it was started in. In git-bash for example I would kick it off like this gui.exe &. This will place it into the background but allows it to write back to the shell. In PowerShell I can do the following:

& `C:\pathTo\gui.exe` | Out-Default

This will write back to the console but will block the shell.

I can also do the following:

Start-Job {& `C:\pathTo\gui.exe` | Out-Default}

But in this case I would have to call Receive-Job (maybe with -Keep) to extract the messages.

Is there a way to have the process both print to Out-Default as well as run in the background. I'm also not sure why I have to force the pipe to | Out-Default as both in cmd.exe and bash it can print the messages. PSversion is 5.0.10586.117.

Edit
As per the suggestion of @metix:
Start-Process -NoNewWindow 'C:\pathTo\gui.exe This does put it into the background but doesn't print back to the console. If I add -RedirectStandardOutput C:\tmp\testout.txt, then this writes to testout.txt. Is there a way to RedirectStandardOutput to the console?

Upvotes: 0

Views: 1464

Answers (1)

Maximilian Etti
Maximilian Etti

Reputation: 230

this should run the process in the background and also prints to console:

Start-Process -NoNewWindow 'C:\pathTo\gui.exe'

Upvotes: 1

Related Questions