Alex Rivera | Logout

How do I get the output of an external command in Perl?

Asked 2009-09-25T14:09:22.147
24

I want to have output of Windows command-line program (say, powercfg -l) written into a file which is created using Perl and then read the file line by line in a for loop and assign it to a string.

Edit
Report

1 Answer

24
system 'powercfg', '-l';

is the recommended way. If you don't mind spawning a subshell,

system "powercfg -l";

will work, too. And if you want the results in a string:

my $str = `powercfg -l`;
answered 2009-09-16T14:33:57.733

Your Answer