Sign in to follow this  
Followers 0
wisem2540

Capturing output of PSexec using RUN

8 posts in this topic

#1 ·  Posted (edited)

Hello all,

I made a script so that I can run Powercfg from command line, and get some data, and it works fine.  But when I add PSexec to the mix, autoit fails to get all of the output

Script

$Computer = "localhost"

$iPID = Run (@ComSpec & " /k " & "C:\PsExec.exe \\" & $Computer & " powercfg /l", "",@SW_SHOW,0x2)



; Wait until the process has closed using the PID returned by Run.
    ProcessWaitClose($iPID)

     Local $sOutput = StdoutRead($iPID)

MsgBox (0,"output", $sOutput)

If I run it manually, I see all the output.  Running it like this, I only get the first line which is something like "Active Power Scheme"

Any input would be apreciated

Edited by wisem2540

Share this post


Link to post
Share on other sites



in the run command, change the 0x2 parameter (that is $STDOUT_CHILD) with 0x8 (that is $STDERR_MERGED) so you will also see (and catch) what happens on the error stream.....


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Very interesting indeed.  So now here is what I get....

PsExec v2.11 - Execute processes remotely
Copyright © 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com

Existing Power Schemes (* Active)
Connecting to localhost...

Starting PSEXESVC service on localhost...

Connecting with PsExec service on localhost...

Starting powercfg on localhost...

powercfg exited on localhost with error code 0.

 

 

So maybe Its launching a different process?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

......

 

So maybe Its launching a different process?

 

yes, it seems that psexec launches your command (powercfg /l) in another process, and doing so, the "stdout" of the last launched process, does not return back to the initial caller.

Maybe the I/O redirection chain is not properly piped back and the stream is lost somewhere

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Anyone have any other ideas on this?

Share this post


Link to post
Share on other sites

Redirects the output in a local file and reads the file :

$sOutput = ""
$Computer = "localhost"

$res = RunWait(@ComSpec & " /c c:\PsExec.exe \\" & $Computer & " powercfg /l > " & @TempDir & "\powercfg.txt", "", @SW_HIDE)
If $res = 0 Then
    $sOutput = FileRead(@TempDir & "\powercfg.txt")
    FileDelete(@TempDir & "\powercfg.txt")
    MsgBox(0, "", $sOutput)
EndIf

Share this post


Link to post
Share on other sites

I dont know why I didnt think of this...  it works!  Thank you so much

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0