How to capture the standard output of command in python script
for example , I want to check if tar command success or not and results will be return in stndStatus value
import commands
def runCommandAndReturnValue():
status,output = commands.getstatusoutput(" tar xvf Test.tar ")
return stndStatus
other example - its like $? in shell scripts so stndStatus will be the value of $?
I need to redirect the output to DEVNULL:
import subprocess
import os
FNULL = open(os.devnull, 'w')
retcode = subprocess.call(['tar', 'xvf', 'test.tar'],
stdout=FNULL,
stderr=subprocess.STDOUT)
print retcode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With