Basic HTML version of Foils prepared March 30 97

Foil 75 Execution of UNIX Commands -- system (Chapter 15 of Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 system("shellscript"); # dispatchs shellscript to be execute by /bin/sh and anything allowed by shell is allowed in argument
  • system returns code returned by shellscript
2 system("date > tempfil"); # executes UNIX command date returning standard output from date to file tempfil in current directory
3 system("rm *") && die ("not allowed\n"); # terminates if error in system call as shell programs return nonzero if failure (opposite of open and most PERL commands)
4 Variable Interpolation is done in double quoted arguments and so one can include Perl variables in arguments of system
5 $prog="nobel.c"; system("cc -o $prog"); # (I) is equivalent here to
6 $ccompiler="cc";
7 system($ccompiler,"-o","nobel.c"); # (II) but in general not identical as in first form (I) shell interprets command list but in second form (II) the arguments are handed directly to command given in first entry in list given to system

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997