import java.io.*; import java.awt.*; import java.awt.event.*; import java.lang.Process; public class ExecuteCommands extends Frame { private TextArea commandWindow; private int ev = 0; public ExecuteCommands() { super ("ExecuteCommands"); commandWindow = new TextArea( "", 0,0, TextArea.SCROLLBARS_VERTICAL_ONLY); add (commandWindow, BorderLayout.CENTER); setSize(400, 150); setVisible( true ); commandWindow.setEditable(false); commandWindow.setVisible(true); } public void runCommandServer(String commandString) { commandWindow.append("\nCommand to be Executed = " + commandString); RunCommand(commandString); } //*************************************************** // Execute the PC command //*************************************************** public void RunCommand(String CommandtoRun) { try { Runtime rt = Runtime.getRuntime(); Process ps = rt.exec(CommandtoRun); try { ps.waitFor(); } catch (IllegalArgumentException ia) { commandWindow.append("Illegal Argument " + ia);} catch (InterruptedException i) { commandWindow.append("waitFor() method failed..." + i + "\n"); } ev = ps.exitValue(); if (ev == 1) {commandWindow.append("Command " + CommandtoRun + "ended abnormally\n");} commandWindow.append("\n" + CommandtoRun + " completed normally"); } catch (IOException e) { commandWindow.append("Command did not start :" + e + "\n"); } } //*************** // Main method //*************** public static void main (String args[]) { ExecuteCommands s = new ExecuteCommands(); s.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); }}); String commandIn = args[0]; s.runCommandServer(commandIn); } }