//File: cat.java //CS 471 - Operating Systems Project //Dennis Pereira, Ely Soto, John Cavalieri //The cat command takes files as arguments and concatenates them //the output is printed to the STDOUT, unless otherwise specified by an //output redirection //if the cat command is given two filenames as arguments, it will open both files //append them together and display them or output them to the desired file import java.io.*; public class cat extends VMachine { public cat() { } public void run() { String input = ""; String line = ""; BufferedReader inputStream = null; //if there are no args, then wait for the user to enter something if(args.length == 0) { try { input = sysapi.Read(IN); } catch(IOException ex) { System.out.println(ex); } } //for each input argument for(int i = 0; i < args.length || input.compareTo("") != 0; i++) { try { if(i=args.length) { input = sysapi.Read(IN); } else { input = ""; } } //if the file is not found then proceed without that file catch(FileNotFoundException e) { try { //tell user, the file is not found sysapi.Write(OUT,"File not found.\n"); //reduce the size of the arg list if(i == args.length-1) { break; } else if(args.length > 0) { //use the next file in the argument list i++; input = args[i]; } else { input = sysapi.Read(IN); if(input.compareTo("")==0) { break; } } } catch(Exception ex) { System.out.println(ex); break; } } //if there is something wrong with the file catch(IOException ioex) { System.out.println(ioex); try { //tell the user about the problem sysapi.Write(OUT,"Error reading from file.\n"); break; } catch(Exception ex) { System.out.println(ex); } } catch(Exception e3) { System.out.println(e3); break; } } sysapi.Exit(vmh,owner); } }