Trying the below I get a file Import_Conf_Output.txt2
created as empty, can anyone tell me what is wrong?
cmd1 = 'my command'
os.system(cmd1 + "1>&/home/s_admin/Import_Conf_Output.txt" + "2>&/home/s_admin/Error.txt")
Trying the below I get a file Import_Conf_Output.txt2
created as empty, can anyone tell me what is wrong?
cmd1 = 'my command'
os.system(cmd1 + "1>&/home/s_admin/Import_Conf_Output.txt" + "2>&/home/s_admin/Error.txt")
As noted in a comment and another answer, your command string is missing spaces. Thus the command you are sending to the shell is:
my command1>&/home/s_admin/Import_Conf_Output.txt2>&/home/s_admin/Error.txt
That said, the subprocess module is meant to replace os.system (and other similar devices). From the docs, the replacement for your command would be:
subprocess.call('my command' + ' 1> /home/s_admin/Import_Conf_Output.txt 2> /home/s_admin/Error.txt', shell=True)
You may want to look through the subprocess module's documentation to see if there is a better way to accomplish what you are doing.
Edit: To work given the command line as provided, the ampersands also should be removed from the redirection, as the different output streams are not going to be combined.
However, as gbtimmon noted in a comment, you can specify stdout and stderr in subprocess.call. The following line, using the ls
command in place of my command
, sent the output to ls.out. Since there was no error, ls.err was empty.
subprocess.call('ls', stdout=open('ls.out', 'w'), stderr=open('ls.err', 'w'))
your should call as:
cmd1 = 'my command'
os.system(cmd1 + " 1>/home/s_admin/Import_Conf_Output.txt" + " 2>/home/s_admin/Error.txt")