python 2 subprocess check_output not returning error output -
i have method
def do_sh_shell_command(string_command, env_variables=none): cmd = shlex.split(string_command) try: p = subprocess.check_output(string_command, shell=true, env=env_variables) # shell=true means sh shell used except subprocess.calledprocesserror e: print 'error running command: ' + '"' + e.cmd + '"' + ' see above shell error' print 'return code: ' + str(e.returncode) return e.returncode, e.cmd return 0, p which work reason doesn't return error output specfici command
def hold_ajf_job(job_order_id): #print 'ctmpsm -updateajf ' + job_order_id + ' hold' return do_sh_shell_command('ctmpsm -updateajf ' + job_order_id + ' hold') hold_ajf_job('0e4ba') do_sh_shell_command('lsl') output:
ctmpsm -updateajf 0e4ba hold error running command: "ctmpsm -updateajf 0e4ba hold" see above shell error return code: 1 /bin/sh: lsl: not found error running command: "lsl" see above shell error return code: 127 when run command ctmpsm -updateajf 0e4ba hold form normal shell below error output
ctmtest1-tctmsv80 [288] ctmpsm -updateajf 0e4ba hold failed hold orderno 0000e4ba. (rc=jobstatincm). this different un-useful error output in python code , can't life of me figure out why?
update:
trying stderr=subprocess.stdout
def do_sh_shell_command(string_command, env_variables=none): cmd = shlex.split(string_command) try: p = subprocess.check_output(string_command, stderr=subprocess.stdout, shell=true, env=env_variables) # shell=true means sh shell used except subprocess.calledprocesserror e: print 'error running command: ' + '"' + e.cmd + '"' + ' see above shell error' print 'return code: ' + str(e.returncode) return e.returncode, e.cmd return 0, p output:
error running command: "ctmpsm -updateajf 0e4ba hold" see above shell error return code: 1 error running command: "lsl" see above shell error return code: 127 now errors have disappeared?
as documented, when check_output raises exception, places output of command in output attribute of exception object. can following:
try: p = subprocess.check_output(string_command, stderr=subprocess.stdout, shell=true, env=env_variables) except subprocess.calledprocesserror e: print e.output print 'error running command: ' + '"' + e.cmd + '"' + ' see above shell error' print 'return code: ' + str(e.returncode) return e.returncode, e.cmd return 0, p
Comments
Post a Comment