os.system and subprocess odd behavior
conor.robinson at gmail.com
Fri Dec 14 19:13:38 CET 2012
Example of the issue for arguments sake:
Platform Ubuntu server 12.04LTS, python 2.7
Say file1.txt has "hello world" in it.
subprocess.Popen("cat < file1 > file2", shell = True)
subprocess.call("cat < file1 > file2", shell = True)
os.system("cat < file1 > file2")
I'm finding that file2 IS created, but with 0bytes in it, this happens when I try any sort of cmd to the system of the nature where I'm putting the output into a file.
I've made sure it isn't a permission issue. The command runs fine from the cmd line and python is being run with super user privileges. Strait from the terminal I get a hello world copy as file2... as expected.
I would like python to simply exec the cmd and move on.... I don't want to read and write the stdout ect into python and write it to a file. Any thoughts as to why this creates file2, but no data appears? Is there a better way to do this?
More information about the Python-list