Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How do I use a literal comma in a system command

Reply
Thread Tools

How do I use a literal comma in a system command

 
 
Tim
Guest
Posts: n/a
 
      04-19-2007
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

 
Reply With Quote
 
 
 
 
Gary E. Ansok
Guest
Posts: n/a
 
      04-19-2007
In article <(E-Mail Removed) .com>,
Tim <(E-Mail Removed)> 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."
 
Reply With Quote
 
 
 
 
Tim
Guest
Posts: n/a
 
      04-20-2007

> 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

 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      04-20-2007
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
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      04-20-2007
Joe Smith <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
pre-processor command to resolve string literal to individual char values steve.lorimer@gmail.com C++ 0 03-29-2007 10:26 AM
Syntax for literal "s on Windows command line John F C Programming 7 02-02-2006 02:50 AM
float: use of comma's versus dots: 12,2 or 12.2 nicholas ASP .Net 2 11-18-2004 03:31 PM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM



Advertisments