Second - you are already doing it right, if I understand what you want to do. eg:
will print foo to the screen.#!/usr/bin/perl -w use strict; system("echo foo");
There are basically three ways to run system commands (there's a lot more, but for now these will do:
The standard out of the command will be printed to the screen and the perl variable $res is the return value of the command (ie. 0 for successful execution).#!/usr/bin/perl -w use strict; my $res = system("/sys/command");
The other way is with backticks which are the backwards apostraphes on your keyboard. eg:
Thi this case, nothing is printed to your screen and the perl variable $res is set to the entire standard out of your command.#!/usr/bin/perl -w use strict; my $res = `/sys/command`;
The third way is to treat it like a file pipe - this way is best for a lot of output:
Which way is best depends on what you're trying to achieve.#!/usr/bin/perl -w use strict; my $file_handle; open $file_handle, "/sys/command |" or die "unable to open command as +pipe"; while my $line = ( <$file_handle> ) { chomp $line; # remove new line do_something( $line ); }
In reply to Re: Need to display output from shell
by aufflick
in thread Need to display output from shell
by ramaks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |