os.system and subprocess odd behavior

Dieter Maurer dieter at handshake.de
Sat Dec 15 02:12:15 EST 2012


py_genetic <conor.robinson at gmail.com> writes:

> Example of the issue for arguments sake:
>
> Platform Ubuntu server 12.04LTS, python 2.7
>
> Say file1.txt has "hello world" in it.
      ^^^^^^^^^
Here, you speak of "file1.txt" (note the extension ".txt")

> subprocess.Popen("cat < file1 > file2", shell = True)
> subprocess.call("cat < file1 > file2", shell = True)
> os.system("cat < file1 > file2")

But in your code, you use "file1" (without extension).

If your code really references a non-existing file, you may well
get what you are observing.




More information about the Python-list mailing list