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

Discussion in 'Python' started by Evan, Nov 3, 2008.

  1. Evan

    Evan Guest

    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
     
    Evan, Nov 3, 2008
    #1
    1. Advertising

  2. 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
     
    Marc 'BlackJack' Rintsch, Nov 4, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    13,240
  2. Eric Layman
    Replies:
    3
    Views:
    630
    Rad [Visual C# MVP]
    Apr 14, 2007
  3. Evan
    Replies:
    3
    Views:
    522
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  4. Replies:
    10
    Views:
    1,227
    Anno Siegel
    Apr 17, 2006
  5. vikrant
    Replies:
    8
    Views:
    366
    vikrant
    May 17, 2007
Loading...

Share This Page