os.system and subprocess odd behavior

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Dec 17 18:16:44 CET 2012


On 17 December 2012 16:39, py_genetic <conor.robinson at gmail.com> wrote:
> Thanks for verifying this for me Steven.  I'm glad you are seeing it work.  It's really the strangest thing.
>
> The issue seems to be with the " > outfile.txt" portion of the command.
>
> The actual command is running a query on a verticalDB and dumping the result.  The EXACT command run from the command line runs just fine.
>
> Even if I use the simple cat command to and out file as just a simple test case...  The file is created with zero bytes (see below)... but its as if python moves on or gets an 0 exit code after the first part of the cmd is executed  and no data is written.
>
> -rw-r--r-- 1 root root        0 Dec 14 15:33 QUAD_12142012203251.TXT
>
> Any thoughts as to why on my end this may happen?

Because of the root permissions on the file? What happens if you write
to a file that doesn't need privileged access?

Instead of running the "exact command", run the cat commands you
posted (that Steven has confirmed as working) and run them somewhere
in your user directory without root permissions.

Also you may want to use subprocess.check_call as this raises a Python
error if the command returns an error code.


Oscar



More information about the Python-list mailing list