Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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
Re: Using System command
by thomas895 (Hermit) 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.

    ~Thomas~
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-11-29 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls