PSHELL and Receive-Job

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
I have created a test .ps1 file to show a problem;
Code:
$ScriptBlock = {$J = New-Object -com jlcutils.cMath; $J.ppp(6.59)}
$MyJob = start-job -scriptblock $ScriptBlock -RunAs32
$MyJob | Wait-Job | Receive-Job
Remove-Job $MyJob
When I invoke it using Powershell from TCC, the result is returned to the console.

When I invoke it using the pshell command, the result is not returned to the console.

In my .ps1 file, Receive-Job returns the result to the console.

Can pshell be made to work with Receive-Job?

This may be related to this thread.

Joe
Code:
TCC  21.01.49 x64   Windows 7 [Version 6.1.7601]
Copyright 2017 JP Software Inc.  All Rights Reserved
Your evaluation period expires in 27 days.
You can buy Take Command, TCC, and CMDebug at https://jpsoft.com

[c:\utils]powershell -file 32bitCOM.ps1
2.99186

[c:\utils]pshell 32bitCOM.ps1

[c:\utils]
 
#3
I just updated to latest version of TCC build, and result is now being returned to the console.
Code:
TCC  21.01.50 x64   Windows 7 [Version 6.1.7601]
TCC Build 50   Windows 7 Build 7601  Service Pack 1

[c:\utils]pshell 32bitcom.ps1
2.99186
I created a .BTM file;
Code:
@setlocal
ver /r
pshell /s "$ScriptBlock = {$J = New-Object -com jlcutils.cMath; $J.ppp(6.59)}"
pshell /s "$MyJob = start-job -scriptblock $ScriptBlock -runas32"
pshell /s "$MyJob | Wait-Job | Receive-Job"
pshell /s "Remove-Job $MyJob"
@endlocal
which produced;
Code:
c:\utils>32bitcom.btm
ver /r

TCC-RT  21.01.50 x64   Windows 7 [Version 6.1.7601]
TCC-RT Build 50   Windows 7 Build 7601  Service Pack 1
pshell /s "$ScriptBlock = {$J = New-Object -com jlcutils.cMath; $J.ppp(6.59)}"
pshell /s "$MyJob = start-job -scriptblock $ScriptBlock -runas32"
pshell /s "$MyJob | Wait-Job | Receive-Job"
2.99186
pshell /s "Remove-Job $MyJob"
...so Receive-Job works just as it does under PowerShell, that is, returning result to console.

Joe
 

rconn

Administrator
Staff member
May 14, 2008
10,292
90
#4
This is the reply from the nsoftware developers:

"I believe the issue here is that the output from the job is not making its way to the general output stream that Scripting Integrator reads from. Could you try assigning the results of Receive-Job to a variable and then explicitly invoking Write-Output with that result? So, something like this:

$ScriptBlock = {$number = 5 + 5; $number}
$MyJob = Start-Job -scriptblock $ScriptBlock -RunAs32
$output = $MyJob | Wait-Job | Receive-Job
Write-Output $output
Remove-Job $MyJob

According to my tests, calling EvalFile() on that script correctly returns '10'. Could you give that a try and let me know what you see?"
 
#5
Yes, the method of assigning the result of Receive-Job to a variable works, and Output-Host displays the result.

Please note that, as I said earlier, updating to 21.01.50 fixed the problem. Receive-Job now works just as it does under PowerShell, that is, returning result to console.

This script;
Code:
$ScriptBlock = {$number = 5 + 5; $number}
$MyJob = Start-Job -scriptblock $ScriptBlock -RunAs32
$MyJob | Wait-Job | Receive-Job
Remove-Job $MyJob
returns the result to the console, without the need to assign the result of Receive-Job to a variable.

Joe