Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-29-2007, 09:25 PM   #1
LQ Newbie
Registered: Oct 2007
Posts: 26

Rep: Reputation: 15
Perl - how to capture output of a command with more than one args


i'm writing a perl script where i need to run a user defined command (a shell script) and capture the output.

i can do this as follows and it works fine:

my @list = `mycommand arg1 arg2`;
however, in the above example, i hard-coded the arg1, arg2 inside the backticks. if i want to declare a scalar variable, which basically holds the value as:

my $x = "arg1";
my $y = "arg2";

my @list = `mycommand $x $y`; //does not work 
my @list = `mycommand $x`; // works
Am I executing the line that does not work above in a wrong way? When I say 'does not work' I mean that when I iterate over my list, it doesn't have anything in it.

Any guidance will be helpful. thanks.

Last edited by new_2_unix; 11-29-2007 at 09:59 PM.
Old 11-29-2007, 11:19 PM   #2
Registered: Jan 2006
Distribution: Ubuntu 9.04, Fedora 10
Posts: 76

Rep: Reputation: 17
Actually looked this up a couple minutes ago for myself...

You can use the ARGV array to get your variables, and add them all either into a string, or an array. below is the method for a single string...

For example...

$args = "";
foreach (@ARGV) {
  $args = $args," ",$_;
`command $args`;
Where I looked this up from a bit before reading this...
Old 11-29-2007, 11:55 PM   #3
LQ Newbie
Registered: Oct 2007
Posts: 26

Original Poster
Rep: Reputation: 15
That works!!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
processing command args in bash slzckboy Programming 16 10-18-2017 04:12 AM
Capture partial output from `date` command tekmann33 Linux - Newbie 7 12-27-2006 02:09 PM
can't capture 'at' command standard output to a file bartoni Linux - General 3 02-28-2006 04:52 PM
perl: passing 2 individual arrays/lists as args johnMG Programming 12 04-18-2005 04:49 PM
>>> control mplayer with command args??? nibjb Linux - Software 0 07-17-2003 12:09 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration