Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 wandering the Monastery: (8)
As of 2014-07-30 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls