# This is a comment line use to comment as below.
# Compile, Link, List, and Execute command procedure.
The $# is set by the shell to determine the number of arguments passed in. The symbol combination $1 is the first parameter on the command line ($2 is the second and so on up to $9 - if more are needed there is a shift function to handle that situation).
If the command “
compexecp” is executed, there are zero (0) parameters and the message AIncorrect number of arguments@ is printed.
Likewise, if “
compexecp test1 test2” is executed the same message will appear. If the command “
compexecp test1” is executed, then “$#” is 1 and “$1” is “test1”. Thus the commands executed are:
javac test1.java
cat test1.java
java test1
Also note that if you typed compexecp test1.java, the first command would fail (i.e., javac test1.java.java) as would the others. This illustrates that the item on the command line is directly substituted for the parameter and that you should use the name without extensions on the command line.
Input from data files is accomplished through standard shell indirection. Two standard system files: System.in and System.out are used for input and output. By default, these files are associated with your keyboard and screen. In batch mode, there is no terminal associated with your job. This means an immediate EOF - end of file - is encountered when using input files in the batch mode. The solution is to redirect the input (and possibly output) to files. An example command file (where input is to come from the file called lab1in.dat and output is to lab1out.dat - in the current directory) would be:
# This is the file clg
# Compile, Link, and Execute command procedure.
javac $1.java
cat $1.java
java $1 < $2 > $3
If the
above command file is called clg, then the batch (background) run may be submitted using the following command from the command line:
prompt% clg test1 lab1in.dat lab1out.dat &
The command will compile, link and execute the program “test1.java” using “lab1in.dat” for input and “lab1out.dat” for output. The “&” at the end places the command file execution in batch (background) mode for execution at a lower priority. You will receive a process number when batch execution starts and an exit notification when execution terminates.
You may obtain a copy of your output by printing out the file (i.e., lab1out.dat in the example above) or by using the typescript utility.