Basic HTML version of Foils prepared Sept 20 97

Foil 69 Execution of UNIX Commands -- system

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


1 system("shellscript"); # dispatchs shellscript to be executed 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:
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 Sun Sep 21 1997