0

I am running PSExec tool through subprocess. If psexec (not the tool on the remote computer) fails to initiate, I need to break. Hence, I am capturing all the command prompt output in a file and parsing it:

logfile = file('Ocd_Log.txt','w')

try:

  process = subprocess.Popen(r'"C:\Program Files (x86)\PSTools\PsExec.exe" -s -i 1 -d -u administrator -p pwd \\10.200.20.20 cmd.exe /k "C:\Osprey_OCD_Daemon_xtensa_9.lnk"', stdout = subprocess.PIPE,stderr = subprocess.PIPE)

  for line in process.stderr:
    print ' '
    sys.stderr.write(line)
    logfile.write(line)
   process.wait()

The above code works good and captures all the command line to the logfile. But I am unable to understand why I need to capture the output through process.stderr and not process.stdout. Please let me know.

1 Answer 1

1

The program choose stdout or stderr (in your case PsExec.exe, u cant fix it). In common, stderr is used for debug data, it is exactly what logfile is!

Sign up to request clarification or add additional context in comments.

2 Comments

I wonder who downvoted this. This is just the truth. PsExec.exe writes to stderr and therefore the data is available on stderr only.
What I got is it depends on the process whether it will give output on stdout or stderr. For Psexec it is stderr and not stdout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.