PSHELL Error?

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
 
May 20, 2008
9,198
60
Syracuse, NY, USA
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.
 
May 20, 2008
9,198
60
Syracuse, NY, USA
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.
 
May 20, 2008
9,198
60
Syracuse, NY, USA
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,930
97
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.
 
May 20, 2008
9,198
60
Syracuse, NY, USA
Definitely not. You're asking TCC to close the PowerShell interpreter and then evaluate an expression in the now nonexistent interpreter. That cannot possibly end well.
PSHELL /C alone gives a usage message. I figured it'd mean execute the string and close when done.
 

rconn

Administrator
Staff member
May 14, 2008
10,930
97
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."
 
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
 
Aug 23, 2010
335
5
Why do you Write-Host in first place?
It will write directly to the console, and rarely, if ever, actually needed.
 
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
 
Thanks for the link.

If I have to go through and re-write my .PS1 files so that Write-Host works with the PSHELL command, I'll go back to doing
Code:
powershell -file whatever.ps1
or
Code:
powershell -command whatever
and forget about using the PSHELL command.

Joe