Jump to content

Capturing output of PSexec using RUN


Go to solution Solved by jguinch,

Recommended Posts

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
Link to comment
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.....

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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?

Link to comment
Share on other sites

......

 

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

  • Solution

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...