Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write-Host not working in ScriptBlock #50

Closed
howardthu opened this issue Dec 4, 2015 · 6 comments
Closed

Write-Host not working in ScriptBlock #50

howardthu opened this issue Dec 4, 2015 · 6 comments

Comments

@howardthu
Copy link

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

@proxb
Copy link
Owner

proxb commented Dec 4, 2015

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
Copy link
Author

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
Copy link
Owner

proxb commented Dec 5, 2015

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
Copy link
Owner

proxb commented Dec 7, 2015

Duplicate of #20

@proxb proxb closed this as completed Jan 8, 2016
@MarkKharitonov
Copy link

MarkKharitonov commented May 19, 2019

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
Copy link
Contributor

MVKozlov commented May 19, 2019

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants