Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   How do I use a literal comma in a system command (http://www.velocityreviews.com/forums/t902752-how-do-i-use-a-literal-comma-in-a-system-command.html)

Tim 04-19-2007 10:52 PM

How do I use a literal comma in a system command
 
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


Gary E. Ansok 04-19-2007 11:18 PM

Re: How do I use a literal comma in a system command
 
In article <1177023172.675724.213680@b58g2000hsg.googlegroups .com>,
Tim <tbrazil@perforce.com> 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."

Tim 04-20-2007 12:10 AM

Re: How do I use a literal comma in a system command
 

> 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


Joe Smith 04-20-2007 08:57 AM

Re: How do I use a literal comma in a system command
 
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

anno4000@radom.zrz.tu-berlin.de 04-20-2007 09:12 AM

Re: How do I use a literal comma in a system command
 
Joe Smith <joe@inwap.com> 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


All times are GMT. The time now is 07:49 PM.

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