The best way (to my knowledge) to do that is to use backticks, assigning the
result to a scalar (the output doesn't have to be a single line,
or a single word or anything.
For example:
$result=`/bin/tail -15 /var/adm/messages`;
You should be very careful though, if you decide to pass to the command
options from the user's input (for example through a CGI script).
But that's a fact, either you use backticks or system.
| [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] |
system() doesn't gather the output of the executed program, it just returns the exit status. With backticks, you can collect the output. You could also open a pipe from a command:
open(PIPE, "command |") or die $!;
while(<PIPE>) {
# ... do something
}
| [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] |
You may want to see the following items:
perldoc -f system
perldoc -f exec
perldoc -q command
| [reply] [Watch: Dir/Any] |