Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message
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?
Post Follow-up to this messagemiracle_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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.