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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Evan

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

    Hello -

    i'm trying to call subprocess.pope n 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.Pope n(["goest",'-f \'\"%s %s\" name addr\' ',
    'file_name'], shell=True)

    It always failed.

    I also try like so:

    p = subprocess.Pope n(["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

    #2
    Re: problem with single-quote and double-quote when using subprocess.

    On Nov 4, 8:47 am, Evan <xdi...@gmail.c omwrote:
    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.

    Comment

    • MRAB

      #3
      Re: problem with single-quote and double-quote when using subprocess.

      On Nov 3, 10:47 pm, Evan <xdi...@gmail.c omwrote:
      Hello -
      >
      i'm trying to call subprocess.pope n 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.Pope n(["goest",'-f \'\"%s %s\" name addr\' ',
      'file_name'], shell=True)
      >
      It always failed.
      >
      I also try like so:
      >
      p = subprocess.Pope n(["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.Pope n(["goest", "-f", "' \"%s %s\" name addr '",
      "file_name"], shell=True)

      (Untested)

      Comment

      • Marc 'BlackJack' Rintsch

        #4
        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.c omwrote:
        >i'm trying to call subprocess.pope n 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.Pope n(["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

        Comment

        Working...