proxb / PoshRSJob

Provides an alternative to PSjobs with greater performance and less overhead to run commands in the background, freeing up the console and allowing throttling on the jobs.
MIT License
542 stars 87 forks source link

Write-Host not working in ScriptBlock #50

Closed howardthu closed 8 years ago

howardthu commented 8 years ago

It doesn't do anything. Write-Host does nothing when enclosed in the ScriptBlock. Echo works, but it's not the same.

proxb commented 8 years ago

Yea, echo is an alias for Write-Output. Can you provide an example of the code you are trying to use? Are you expecting the write-host stream to be displayed when using receive-rsjob? There is a pull request currently submitted that should fix that issue. I just need to review it and merge it.

howardthu commented 8 years ago

echo is the alias of write-output. Write-Host has options such as -NoNewline, -ForegroundColor. I can provide an example.

Start-RSJob -ScriptBlock { Write-Host "test" echo "test2" }

Get-RSJob | Wait-RSJob Get-RSJob | Receive-RSJob

In this example, only "test2" gets outputted.

Also, on an unrelated note, can you give me an example on how to call a function (declared outside the scriptblock) from within the scriptblock? I tried using a variable but it didn't seem to work. Thanks

proxb commented 8 years ago

That is expected behavior as of right now. You can track the stream in the rsjob object but as I mentioned above, there is a pull request that I need to review which should add this capability. For the function outside of the rsjob, use the -FunctionsToLoad parameter and supply the function name. An example can be found here: http://blogs.technet.com/b/heyscriptingguy/archive/2015/11/29/weekend-scripter-a-look-at-the-poshrsjob-module.aspx

proxb commented 8 years ago

Duplicate of #20

MarkKharitonov commented 5 years ago

It still does not work.

Receive-RSJob -Job (Wait-RSJob -Job (Start-RSJob -ScriptBlock { Write-Host "hello" }))

prints nothing.

Invoke-Parallel, on the other hand, works correctly:

0 | Invoke-Parallel { Write-Host $_ }

outputs 0.

MVKozlov commented 5 years ago

on PS v5.0+ Host stream converted into Information stream but PoshRSJob still does not support Information stream. (#129)

PS C:\> Receive-RSJob -Job (Wait-RSJob -Job (Start-RSJob -ScriptBlock { Write-Host "hello" }))
PS C:\> $j = Get-RSJob
PS C:\> $j.InnerJob.Streams
Error       : {}
Progress    : {}
Verbose     : {}
Debug       : {}
Warning     : {}
Information : {hello}