PaulHigin / PSThreadJob

A PowerShell module for running concurrent jobs based on threads rather than processes
MIT License
180 stars 18 forks source link

Write-Host output is sent to pipeline #11

Closed ajansveld closed 5 years ago

ajansveld commented 6 years ago

Messages originating from Write-Host or $Host.UI.WriteLine() are sent to the Output stream, which results in Receive-Job sending them to the pipeline:

$result = Start-ThreadJob {Write-Host foo} | Receive-Job -Wait -AutoRemoveJob
$result.Count  # Should be 0

This seems to originate from this code:

           hostUI.Output.DataAdded += (sender, dataAddedEventArgs) =>
            {
                Collection<PSObject> output = hostUI.Output.ReadAll();
                foreach (var item in output)
                {
                    _output.Add(item);
                }
            };

Not sure what the proper fix is, perhaps this can be removed?

ajansveld commented 6 years ago

FYI - I have been running with the _output.Add(item) line removed for several months; it fixes the issue and I have seen no negative side effects.

PaulHigin commented 6 years ago

I just wanted some way to get host output from the job. Otherwise it is lost. I suppose we could make it an option.

ajansveld commented 5 years ago

It looks like the Information stream handling was fixed in #30. Can we now remove the _output.Add(item) line (at least for psVersion.Major >= 5)?

PaulHigin commented 5 years ago

Yeah, I think it can be removed. It was always just a hack to try and capture host writes.

ajansveld commented 5 years ago

Fixed in version 2.0.0.