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.