I have this 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 as 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 but for some reason doesn't return the error output from a 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 I run command ctmpsm -UPDATEAJF 0e4ba HOLD just form the normal shell i get the below error output
ctmtest1-tctmsv80 [288] ctmpsm -UPDATEAJF 0e4ba HOLD Failed to Hold Orderno 0000e4ba. (rc=JOBSTATINCM). This is different to the un-useful error output in my python code and I can't for the 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 as 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 completely disappeared?
cmdis unused in your code.