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
11,391
99
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
11,391
99
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
11,391
99
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
12,340
149
"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
12,340
149
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
11,391
99
Syracuse, NY, USA
WAD. @PSHELL is not returning multiple lines. @PSHELL executes the Powershell expression, and Powershell is writing the DIR output.
Writing it to the console? How is it that "echo %@upper[%@pshell[dir]]" manages to make it all uppercase?
 
May 20, 2008
11,391
99
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
12,340
149
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
636
9
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
 
Similar threads
Thread starter Title Forum Replies Date
M Fixed PSHELL command returns error Support 2
Joe Caverly PSHELL and COM Object in v27 Support 1
Joe Caverly PSHELL in v27 vs. 26 Support 17
vefatica @PSHELL? Support 5
Peter Murschall v27.00.17: PSHELL /S dosn't do nothing Support 8
Joe Caverly PSHELL and NTFS File Streams Support 2
vefatica PSHELL: How pass arguments to script? Support 15
Joe Caverly Using @PSHELL from @EVAL Support 8
vefatica PSHELL and @PSHELL fail the first time in a new TCC. Support 3
Peter Murschall Documentation Question to %@PSHELL Support 4
Joe Caverly PSHELL and @PSHELL errorlevel values Support 4
Joe Caverly PSHELL and out-of-process servers Support 2
Joe Caverly PSHELL /C Support 7
vefatica What happens to PSHELL after 20 seconds? Support 9
Joe Caverly .PS1 script does not work with PSHELL Support 11
Joe Caverly How to use Powershell Profile with PSHELL Support 14
samintz PSHELL's CWD Support 2
Joe Caverly Missing PSHELL in HELP Support 0
Joe Caverly PSHELL Blank Line Display Support 2
vefatica PSHELL? Support 6
Joe Caverly PSHELL and Receive-Job Support 4
Joe Caverly Documentation @PSHELL Support 0
C Copy (sys) error Support 3
T Error: This page can’t be displayed Make sure the web address //ieframe.dll/dnserrordiagoff.htm# is correct. Support 8
kb6ojs How to? "Specified Account Already Exists" error installing TCMD v27 Support 12
samintz How to? Abort on error DO loop Support 10
mfarah Fixed The DATE command produces the wrong error message. Support 1
vefatica ON ERROR terminates DO loop. Support 0
C Google intregration error Support 4
C FB intregration error Support 0
gworley rd (Remove Directory) gives interesting error: Support 2
D How to? Skip removing directory (RMDIR) without error message Support 2
Dmitry L. Kobyakov Documentation Error in the Help: the WINDOW command Support 0
M Strange error messages from TCC in FTP copy Support 7
vefatica Error message from TOUCH Support 2
R FIND command error Support 9
fpefpe Python dll error Support 3
D error in help documentation? Support 0
R FOR usage error from TCC but not from CMD Support 16
K_Meinhard Help file error Support 1
X small translation error. Support 0
W pdir returns diff results between tcc and tcmd - one is an error msg Support 5
Dmitry L. Kobyakov From old version: had the setup's error been corrected? Support 6
vefatica Why no error message? Support 2
vefatica ON ERROR and pipes? Support 8
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
Joe Caverly TASKDIALOG Help link error Support 1
J Error "Contents lost before copy" Support 3
vefatica What's causing this error? Support 4
vefatica Error 203? Support 4

Similar threads