Home > Archive > PERL Miscellaneous > September 2004 > processing command line arguments with backticks
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
processing command line arguments with backticks
|
|
| miracle_ks 2004-09-26, 3:55 am |
| Hi All,
I am trying to run a system command in my perl script, such that I
specify some command line options within the script and then take the
next argument from an input file and then the final argument again
within the script:
$command='/bin/somecommand -x -y -z';
$p1=2456;
foreach $item (@in_arr){
print OUT `$command $item $p1`;
}
When i run this, only last item from the input file is run properly
with $p1 argument. For all other items $p1 is not taken into
consideration.
Any help will be appreciated.
Regards
| |
| Brian McCauley 2004-09-26, 9:07 am |
|
miracle_ks wrote:
> I am trying to run a system command in my perl script, such that I
> specify some command line options within the script and then take the
> next argument from an input file and then the final argument again
> within the script:
>
> $command='/bin/somecommand -x -y -z';
> $p1=2456;
> foreach $item (@in_arr){
> print OUT `$command $item $p1`;
> }
>
> When i run this, only last item from the input file is run properly
> with $p1 argument. For all other items $p1 is not taken into
> consideration.
>
> Any help will be appreciated.
You should try to construct a _minimal_ but _complete_ script to
illustrate your problem.
Random shot in the dark, you forgot to chomp() the data that you read
into @in_arr and that data also lacks a newline at EOF.
However if this were the case you'd expect to see errors about 2345 not
being found. Did you perhaps send STDERR somewhere you don't see it?
| |
| Joe Smith 2004-09-27, 8:58 am |
| miracle_ks wrote:
> $command='/bin/somecommand -x -y -z';
> $p1=2456;
> foreach $item (@in_arr){
> print OUT `$command $item $p1`;
> }
>
> When i run this, only last item from the input file is run properly
> with $p1 argument. For all other items $p1 is not taken into
> consideration.
I was able to reproduce your symptoms by using this:
print OUT `$command $item1\n $p1`;
print OUT `$command $item2 $p1`;
The solution is obvious: get rid of the extra \n by using chomp().
-Joe
|
|
|
|
|