Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

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

Reply
 
Old 05-01-2008   #1 (permalink)
kanjasaha


 
 

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
Old 05-01-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

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

kanjasaha@xxxxxx wrote:
Quote:

> 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
Reply

Thread Tools


Similar Threads
Thread Forum
objshell.exec exit code VB Script
StdOut.ReadAll() in VBScript VB Script
Problem with WSH Shell Exec StdOut VB Script
StdOut.ReadAll blocking? VB Script
stdout redirection PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46