Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Using System command

by perlatbest (Initiate)
on Apr 19, 2012 at 23:27 UTC ( #966060=perlquestion: print w/ replies, xml ) Need Help??
perlatbest has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use below command, but not sure why I am not able to store the output value of system command to variable "cmd", as system command output is displaying on screen very fine.

my $cmd = system("find . type f -name \"fname*\") my $cmd = `ls -l`;

Comment on Using System command
Download Code
Replies are listed 'Best First'.
Re: Using System command
by thomas895 (Chaplain) on Apr 19, 2012 at 23:38 UTC

    That's because system only returns 0 if the command was successful. See system. To write the response to a filehandle, use pipe or write a pipe using open.
    Be very careful when just putting user input directly into the command -- it's a big security risk and -T will produce errors.

Re: Using System command
by mbethke (Hermit) on Apr 19, 2012 at 23:41 UTC

    That's because system does not return the STDOUT output of the command but the exit status, see "perldoc -f system". Having two separate constructs for the same job would be redundant.

    If the backticks do what you need, why not just use them?

    Edit: LOL, guess the number of possible wordings was quite limited ...

      Thanks for clarifying on this.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966060]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2016-05-01 00:02 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.