How do I use a literal comma in a system command

T

Tim

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
 
G

Gary E. Ansok

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
 
T

Tim

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
 
J

Joe Smith

Tim said:
$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
 
A

anno4000

Joe Smith said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top