Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

processing command line arguments with backticks
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

Report this thread to moderator Post Follow-up to this message
Old Post
miracle_ks
09-26-04 08:55 AM


Re: processing command line arguments with backticks

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?


Report this thread to moderator Post Follow-up to this message
Old Post
Brian McCauley
09-26-04 02:07 PM


Re: processing command line arguments with backticks
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

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Smith
09-27-04 01:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:25 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.