problem with quote and single-quote when using "subprocess"

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Nov 3 19:08:16 EST 2008


On Mon, 03 Nov 2008 14:45:22 -0800, Evan wrote:

> Hello -
> 
> i'm trying to call subprocess.popen on the 'command-based' function in
> linux.  When I run the command from the shell, like so:
> 
> goset -f ' "%s %s" name addr ' file_name
> 
> it works fine
> 
> however when I try to do it in python like so:
> 
> p = subprocess.Popen(["goest",'-f \'\"%s %s\" name addr\' ',
> 'file_name'], shell=True)
> 
> It always failed.

Yes because ``goset`` (I guess "goest" was a typo!?) has no option
`'-f '"%s %s" name addr' `.  And you should decide if you want to split 
the arguments yourself or if you want to use the shell.  Mixing both 
doesn't make much sense.

If *you* split the arguments, the call should look like this:

p = subprocess.Popen(['goset', '-f', ' "%s %s" name addr ', 'file_name'])

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list