By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,592 Members | 1,569 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,592 IT Pros & Developers. It's quick & easy.

problem with single-quote and double-quote when using subprocess.

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
On Nov 4, 8:47*am, Evan <xdi...@gmail.comwrote:
It always failed.
It also failed.
Does anybody have a good suggestion for this matter? thanks in
advance.
What do you mean by "it failed"? It always helps to paste the actual
error message you received.
Nov 4 '08 #2

P: n/a
On Nov 3, 10:47*pm, Evan <xdi...@gmail.comwrote:
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.
It looks like there are _4_ items on the command line:

goset
-f
' "%s %s" name addr '
file_name

so the call should be:

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

(Untested)
Nov 4 '08 #3

P: n/a
On Tue, 04 Nov 2008 03:26:21 -0800, MRAB wrote:
On Nov 3, 10:47*pm, Evan <xdi...@gmail.comwrote:
>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

It looks like there are _4_ items on the command line:

goset
-f
' "%s %s" name addr '
file_name

so the call should be:

p = subprocess.Popen(["goest", "-f", "' \"%s %s\" name addr '",
"file_name"], shell=True)
The argument after '-f' doesn't have the single quotes at both ends.
They tell the shell that it is just one argument and the shell removes
them before calling ``goset`` (or ``goest``).

Ciao,
Marc 'BlackJack' Rintsch
Nov 4 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.