12
W:> $job = start-job { Write-Output "hi there"; throw "an error!" } | Wait-Job
W:> $job | select *


State         : Failed
HasMoreData   : True
StatusMessage :
Location      : localhost
Command       :  Write-Output "hi there"; throw "an error!"
JobStateInfo  : Failed
Finished      : System.Threading.ManualResetEvent
InstanceId    : 882957a9-a5e0-4876-bd22-0dbd87512f10
Id            : 7
Name          : Job7
ChildJobs     : {Job8}
PSBeginTime   : 3/24/2013 5:52:41 PM
PSEndTime     : 3/24/2013 5:52:47 PM
PSJobTypeName : BackgroundJob
Output        : {}
Error         : {}
Progress      : {}
Verbose       : {}
Debug         : {}
Warning       : {}

Where did my output go? How do I see the standard out/error streams?

1 Answer 1

34

Jobs are running in the background, so they don't write to the console. You have to run Receive-Job after a job completes to collect its output.

Sign up to request clarification or add additional context in comments.

4 Comments

Perfect. thank you sir. I would add that it seems it is important to wait for the job to be complete before trying to receive it.
@GeorgeMauer Indeed. I added this detail to my answer.
I dont see this behaviour. Instead my console randomly gets a blast of output from the job. I'm not using Wait-Job though
You don't have to wait, see my answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.