How do I use a literal comma in a system command

Discussion in 'Perl Misc' started by Tim, Apr 19, 2007.

  1. Tim

    Tim Guest

    Hi

    I'm trying to use a comma a part of my system/exe/open command however
    it is interpreted as a delimiter. The actural command I'm trying to
    execute is:

    p4 obliterate -y @813, 813 # the amperstands and comma are
    meaningful to the command.

    If I use a single obliterate (e.g. "$p4 obliterate -y \@
    $changenumber") the command executes properly. Once I add the comma
    and second \@$changenumber it is interpreted as an additional shell
    command.
    I've tried escaping the comma, double quoting, double escapes, etc.
    Does anyone know how I can successfully passed the comma + second
    argument to the actual "p4" command. Thanks in advance.

    Tim

    The perl looks something like this. $changenumber = 813

    $cmd="$p4 obliterate -y \@$changenumber, \@$changenumber";
    open(OBLITERATE,"$cmd|");
    close(OBLITERATE)

    sh: line 1: ,@813: command not found
    Tim, Apr 19, 2007
    #1
    1. Advertising

  2. In article <>,
    Tim <> wrote:
    >The perl looks something like this. $changenumber = 813
    >
    > $cmd="$p4 obliterate -y \@$changenumber, \@$changenumber";
    >open(OBLITERATE,"$cmd|");
    >close(OBLITERATE)
    >
    >sh: line 1: ,@813: command not found


    Commas (within quoted strings) are not special to Perl or to the shell,
    so I doubt that that is causing your problem.

    I'm going to take a wild guess and say that you are reading
    $changenumber from a file (or from the terminal), and you aren't
    using chomp() to remove the newline from the end of the string.

    Gary
    --
    Customer: "There are smoke and flames coming from my computer."
    Tech Support: "Uh, hang up, unplug the computer from the wall,
    and call the local fire department."
    Customer: "No, I need to know how to do a backup. Fastest possible method."
    Gary E. Ansok, Apr 20, 2007
    #2
    1. Advertising

  3. Tim

    Tim Guest


    > Commas (within quoted strings) are not special to Perl or to the shell,
    > so I doubt that that is causing your problem.
    >
    > I'm going to take a wild guess and say that you are reading
    > $changenumber from a file (or from the terminal), and you aren't
    > using chomp() to remove the newline from the end of the string.
    >
    > Gary
    > --


    Hi Gary

    Ooopps.. As soon as I saw the word chomp I knew you were right. I
    wasn't reading from a file but was indeed reading from a pipe of
    another command. The newline was THERE! Thanks for the help.

    Tim
    Tim, Apr 20, 2007
    #3
  4. Tim

    Joe Smith Guest

    Tim wrote:

    > $cmd="$p4 obliterate -y \@$changenumber, \@$changenumber";
    > open(OBLITERATE,"$cmd|");
    >
    > sh: line 1: ,@813: command not found


    Something to remember in the future: whenever system() or other
    function gives unexpected results, be sure to print the string
    you're about to execute to make sure it is what you think it is.

    print "Opening a pipe to: '$cmd'\n";
    open(OBLITERATE,"$cmd|") or die "Pipe open of '$_' failed: $!\n";

    -Joe
    Joe Smith, Apr 20, 2007
    #4
  5. Tim

    -berlin.de Guest

    Joe Smith <> wrote in comp.lang.perl.misc:
    > Tim wrote:
    >
    > > $cmd="$p4 obliterate -y \@$changenumber, \@$changenumber";
    > > open(OBLITERATE,"$cmd|");
    > >
    > > sh: line 1: ,@813: command not found

    >
    > Something to remember in the future: whenever system() or other
    > function gives unexpected results, be sure to print the string
    > you're about to execute to make sure it is what you think it is.
    >
    > print "Opening a pipe to: '$cmd'\n";
    > open(OBLITERATE,"$cmd|") or die "Pipe open of '$_' failed: $!\n";


    With the shell-invoking one-argument form of system(), a useful variant
    is to replace the actual command with "echo" (under Unix) for a test.
    That way you get to see the command arguments in the form the shell
    passes them on.

    Anno
    -berlin.de, Apr 20, 2007
    #5
    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. nicholas
    Replies:
    2
    Views:
    491
    nicholas
    Nov 18, 2004
  2. John F
    Replies:
    7
    Views:
    677
    CBFalconer
    Feb 2, 2006
  3. Replies:
    0
    Views:
    320
  4. boriq
    Replies:
    4
    Views:
    582
    Tim Golden
    Jun 12, 2008
  5. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    374
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page