Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   problem with single-quote and double-quote when using subprocess. (http://www.velocityreviews.com/forums/t642863-problem-with-single-quote-and-double-quote-when-using-subprocess.html)

Evan 11-03-2008 10:47 PM

problem with single-quote and double-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

alex23 11-04-2008 12:53 AM

Re: problem with single-quote and double-quote when using subprocess.
 
On Nov 4, 8:47*am, Evan <xdi...@gmail.com> wrote:
> 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.

MRAB 11-04-2008 11:26 AM

Re: problem with single-quote and double-quote when using subprocess.
 
On Nov 3, 10:47*pm, Evan <xdi...@gmail.com> 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.
>
> 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)

Marc 'BlackJack' Rintsch 11-04-2008 12:24 PM

Re: problem with single-quote and double-quote when usingsubprocess.
 
On Tue, 04 Nov 2008 03:26:21 -0800, MRAB wrote:

> On Nov 3, 10:47*pm, Evan <xdi...@gmail.com> wrote:
>> 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


All times are GMT. The time now is 09:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.