50 likes | 148 Views
Process Management. As a scripting language Perl provides the ability to run programs inside a Perl script. For example I could run a “dir” command inside of Perl, munge the output, and print my own version of it You do this using system() exec(). system().
E N D
Process Management • As a scripting language Perl provides the ability to run programs inside a Perl script. • For example I could run a “dir” command inside of Perl, munge the output, and print my own version of it • You do this using • system() • exec()
system() • Argument specifies the program to run system( “date” ); • Runs the command and returns the exit status of the program system( “data” ) && die “bad command”; • Standard input, standard output, and standard error are inherited
Fancy Stuff • This all works system( “date > date.out” ); $fileName = “date.out”; system( “date > $fileName” ); system ( “dir process.perl” ); system ( “dir”, “process.perl” );
Processes and File Handles • Processes can be started from within file handles • open( DIRPROC, “dir|” ); • All the standard file stuff now applies to the output • @listing=<DIRPROC>; • open( LPR, “|lpr”); • print LPR @listing;
Your Turn!! • Write a Perl script that prints out the names of the directories and then the names of a the files in the current directory.