I’m having trouble checking for errors in python’s subprocess. The subprocess is a sas program. Any wizards have any magic to share? I’d like to avoid searching the sas log for strings and instead rely on the return code.
I’m stuck w/ python 2.7 on a AIX server.
I’m able to invoke a sas program in a variety of ways using python’s subprocess module. I’ve successfully invoked a program using the check_output module, the Popen module or even just the call object. However, for the life of me I cannot get the return code!
Import subprocess
Subprocess.call([‘SAS’,’/path/program.sas’])
Or
Import subprocess
P = subprocess.check_output(“sas /path/program.sas”, stderr=subprocess.STDOUT, shell=True)
Print(p)
Or Import subprocess P = subprocess.Popen(“sas /path/program.sas”, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) proc.wait() Standard_output, standard_error = proc.communicate*( Print(proc.returncode) Or
Import subprocess
Try:
output = subprocess.check_output(‘sas /path/program.sas’, stderr=subprocess.STDOUT, shell=true)
Except subprocess.CalledProcessError as exc:
Print(“Status : Fail”, exc.returncode)
trueandfalse? - Lorinczy ZsigmondSAS ...; echo ReturnStatus=$?it should print 0 for success, non-zero for failure. - Lorinczy Zsigmond