1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PSHELL Error?

Discussion in 'Support' started by Joe Caverly, Sep 13, 2017.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    661
    Likes Received:
    8
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    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.
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    WAD. @PSHELL is not returning multiple lines. @PSHELL executes the Powershell expression, and Powershell is writing the DIR output.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    Unless Microsoft and Intel broke the hardware, TCC and TCMD can't affect CONHOST.
     
  7. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    Not under my control, but I'll contact the Ipworks developers and see if they have a fix / workaround.
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    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.
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    Writing it to the console? How is it that "echo %@upper[%@pshell[dir]]" manages to make it all uppercase?
     
  10. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    PSHELL /C alone gives a usage message. I figured it'd mean execute the string and close when done.
     
  11. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    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. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    661
    Likes Received:
    8
    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
     
  13. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    It means I'll report that back to the developers and see what they say.
     
  14. AnrDaemon

    Joined:
    Aug 23, 2010
    Messages:
    45
    Likes Received:
    1
    Why do you Write-Host in first place?
    It will write directly to the console, and rarely, if ever, actually needed.
     
  15. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    661
    Likes Received:
    8
    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
     
  16. AnrDaemon

    Joined:
    Aug 23, 2010
    Messages:
    45
    Likes Received:
    1
  17. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    661
    Likes Received:
    8
    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
     

Share This Page