PSHELL Error?

#1
Invoking julian.ps1 with PowerShell works, but invoking with PSHELL gives an error.

The problem PowerShell command is Write-Host. If I change Write-Host $JulianDate to just $JulianDate, there is no error, and works just as if called from PowerShell.

I have many .ps1 files that use Write-Host.

Can PSHELL be made to work with Write-Host?

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 29 days.
You can buy Take Command, TCC, and CMDebug at https://jpsoft.com

[c:\utils]pshell julian.ps1
PSHELL: System.Management.Automation.CmdletInvocationException : Cannot invoke this function because the current host
does not implement it.

[c:\utils]powershell -file julian.ps1
7256

[c:\utils]type julian.ps1
#Calculate today's julian date
$Year = get-date -format yy
$JulianYear = $Year.Substring(1)
$DayOfYear = (Get-Date).DayofYear
$JulianDate = $JulianYear + "{0:D3}" -f $DayOfYear
Write-Host $JulianDate
 
#2
I think "PSHELL /s /c dir" worked a few days ago. With build 49, it unceremoniously produces no output. And after one such failure, the command described in the next paragraph also unceremoniously produces no output.

"echo %@PSHELL[dir]" works (except as noted above), giving the entire PowerShell output for "dir". Is all of that the return value of @PSHELL? Normally functions don't return multiple lines.
 
#3
I think "PSHELL /s /c dir" worked a few days ago. With build 49, it unceremoniously produces no output. And after one such failure, the command described in the next paragraph also unceremoniously produces no output.

"echo %@PSHELL[dir]" works (except as noted above), giving the entire PowerShell output for "dir". Is all of that the return value of @PSHELL? Normally functions don't return multiple lines.
And just messing around, executing those two commands (only) rather ramdomly, I've seen TCC dissappear and I've seen it crash with a Windows dialog (didn't get the content and haven't been able to reproduce it).

And (FWIW) since I started using v21, I'm getting an occasional crash in CONHOST.EXE. I had never seen one before.
 
#4
And does @PSHELL leave an interpreter running? Is it supposed to? The first time I "echo %@pshell[dir]" I get a listing of my documents directory. If I "echo %@pshell[cd v:\; dir]" I get a listing of v:\. If I then do "echo %@pshell[dir]" I get the v:\ listing.
 

rconn

Administrator
Staff member
May 14, 2008
10,749
97
#5
"echo %@PSHELL[dir]" works (except as noted above), giving the entire PowerShell output for "dir". Is all of that the return value of @PSHELL? Normally functions don't return multiple lines.
WAD. @PSHELL is not returning multiple lines. @PSHELL executes the Powershell expression, and Powershell is writing the DIR output.
 

rconn

Administrator
Staff member
May 14, 2008
10,749
97
#7
Invoking julian.ps1 with PowerShell works, but invoking with PSHELL gives an error.

The problem PowerShell command is Write-Host. If I change Write-Host $JulianDate to just $JulianDate, there is no error, and works just as if called from PowerShell.

I have many .ps1 files that use Write-Host.

Can PSHELL be made to work with Write-Host?
Not under my control, but I'll contact the Ipworks developers and see if they have a fix / workaround.
 

rconn

Administrator
Staff member
May 14, 2008
10,749
97
#11
I have many .ps1 files that use Write-Host.

Can PSHELL be made to work with Write-Host?
This is the response I got from the developers:

"Sorry to hear you're seeing issues using Write-Host with the Scripting Integrator. As a first test, could you try replacing Write-Host with Write-Output? It sounds like PowerShell is unable to resolve which stream Host should refer to, but I believe the Output stream should be unaffected here. If using Write-Output doesn't resolve the issue please let me know and I'll be happy to take a closer look."
 
#12
Code:
TCC  21.01.51 x64   Windows 7 [Version 6.1.7601]
Copyright 2017 JP Software Inc.  All Rights Reserved
Your evaluation period expires in 24 days.
You can buy Take Command, TCC, and CMDebug at https://jpsoft.com

[c:\utils]pshell julian.ps1
7261
Write-Output does resolve the issue, so does this mean that I have to change Write-Host to Write-Output in all of my .PS1 files?

Joe
 
#15
Code:
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\utils> write-host 'Red on white text.' -ForegroundColor red -BackgroundColor white
Red on white text.
PS C:\utils>
I use colour output with Write-Host in my .PS1 files, which does not work with PSHELL /S, that is, nothing is output to the console.

Joe