468,457 Members | 1,595 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

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

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.

I also try like so:

p = subprocess.Popen(["goest","-f '\"%s %s\" name addr' ",
'file_name'], shell=True)

It also failed.

Does anybody have a good suggestion for this matter? thanks in
advance.

Evan
Nov 3 '08 #1
1 1146
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
Nov 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Yandos | last post: by
3 posts views Thread by Colin J. Williams | last post: by
2 posts views Thread by Gregor Kofler | last post: by
1 post views Thread by =?Utf-8?B?S2F1c2hhbCBNZWh0YQ==?= | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.