Windows Vista Forums

redirect powershell stdout to objShell.Exec.Stdout.ReadAll()(
  1. #1


    kanjasaha Guest

    redirect powershell stdout to objShell.Exec.Stdout.ReadAll()(

    Hi,

    I have a similar problem I am dealing with. Hence posting in this
    discussion chain.

    I have a powershell script text.ps1

    And then I have a .js file which is invoking this text.ps1 using WSH.

    Here is the code:

    ------------------------------------------------------------------


    var objShell = WScript.CreateObject("WScript.Shell");

    var strCMD="powershell c:\\script\\text.ps1"

    WScript.Echo (strCMD)

    var objexec = objShell.Exec(strCMD)

    WScript.Echo (objexec.status)


    /**
    WScript.Echo("stdout");
    WScript.Echo(objexec.StdOut.ReadAll())
    WScript.Echo("stderr");
    WScript.Echo(objexec.StdErr.ReadAll())
    WScript.Echo("ExitCode");
    WScript.Echo(objexec.exitcode)
    **/
    --------------------------------------------------------

    Even after the var objexec = objShell.Exec(strCMD) ran successfully, I
    see the Exec.Status is 0.(The powershell window closed after the
    execution)

    And when I try to display WScript.Echo(objexec.StdOut.ReadAll()),
    the .js script hangs and I have to do CTRL+C to get out to command
    line.


    Is it at all possible to redirect powershell stdout(which is an
    object) to objShell.Exec.Stdout.ReadAll()(which is text I assume).

    Thanks
    Kanja



      My System SpecsSystem Spec

  2. #2


    Marco Shaw [MVP] Guest

    Re: redirect powershell stdout to objShell.Exec.Stdout.ReadAll()(

    kanjasaha@xxxxxx wrote:

    > Hi,
    >
    > I have a similar problem I am dealing with. Hence posting in this
    > discussion chain.
    >
    > I have a powershell script text.ps1
    >
    > And then I have a .js file which is invoking this text.ps1 using WSH.
    >
    > Here is the code:
    >
    > ------------------------------------------------------------------
    >
    >
    > var objShell = WScript.CreateObject("WScript.Shell");
    >
    > var strCMD="powershell c:\\script\\text.ps1"
    You're not calling powershell.exe properly for starters. This should
    help somewhat:

    http://blog.sapien.com/index.php/200...ed-powershell/

    Marco


    --
    Microsoft MVP - Windows PowerShell
    http://www.microsoft.com/mvp

    PowerGadgets MVP
    http://www.powergadgets.com/mvp

    Blog:
    http://marcoshaw.blogspot.com

      My System SpecsSystem Spec

redirect powershell stdout to objShell.Exec.Stdout.ReadAll()( problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changes to stdout, stderr in PowerShell 2.0 John Vottero PowerShell 1 22 Jan 2010
objshell.exec exit code Ruoyu VB Script 2 04 Jun 2009
StdOut.ReadAll() in VBScript tpreitano VB Script 4 26 Feb 2009
Problem with WSH Shell Exec StdOut Paul Randall VB Script 10 20 Jan 2009
StdOut.ReadAll blocking? lucadentella VB Script 2 14 Jul 2008