Programming Perl

Programming PerlSearch this book
Previous: 7.2.55 SelfLoader - Load Functions Only on DemandChapter 7
The Standard Perl Library
Next: 7.2.57 sigtrap - Enable Stack Backtrace on Unexpected Signals
 

7.2.56 Shell - Run Shell Commands Transparently Within Perl

use Shell qw(date cp ps);  # list shell commands you want to use

$date = date();   # put the output of the date(1) command into $date
cp("-p" "/etc/passwd", "/tmp/passwd");  # copy password file to a tmp file
print ps("-ww");  # print the results of a "ps -ww" command

This module allows you to invoke UNIX utilities accessible from the shell command line as if they were Perl subroutines. Arguments (including switches) are passed to the utilities as strings.

The Shell module essentially duplicates the built-in backtick functionality of Perl. The module was written so that its implementation could serve as a demonstration of autoloading. It also shows how function calls can be mapped to subprocesses.


Previous: 7.2.55 SelfLoader - Load Functions Only on DemandProgramming PerlNext: 7.2.57 sigtrap - Enable Stack Backtrace on Unexpected Signals
7.2.55 SelfLoader - Load Functions Only on DemandBook Index7.2.57 sigtrap - Enable Stack Backtrace on Unexpected Signals