subprocess module usage

Akira Li 4kir4.1i at
Mon Sep 1 21:45:22 CEST 2014

Earl Lapus <earl.lapus at> writes:

> Hi,
> I made simple test program using the subprocess module (see attached:
> I ran it passing variations of 'ls' command options.
> I encounter exceptions every time I use '-l' options. Example runs
> where exception occurs:
> # ./ ls -al
> # ./ ls -l
> However, if I pass 'ls' and arguments as one argument, like so:
> #./ 'ls -al'
> exception does not occur.
> I logged output (see ls_test.out).
> So, what could be causing this behavior? Is this expected or is there
> something wrong with how I'm using the subprocess module?

You shouldn't use shell=True with a list argument (sys.argv[1:] is a
list). Specify the command as a string or use shell=False.


More information about the Python-list mailing list