org.ifeth.sehr.lib
Class SysExec

java.lang.Object
  extended byorg.ifeth.sehr.lib.SysExec

public class SysExec
extends java.lang.Object

Run a external process in three ways:

  1. exec: Execute the command, returning immediately even if the command is still running. e.g. printing, facsimile processes
  2. execWait: Execute the command, but don't return until the command finishes. This would be appropriate for sequential commands where the first depends on the second having finished (e.g. javac followed by java).
  3. execPrint: Execute the command and get the output, e.g. a for the UNIX command like ls.
Note that the PATH is not taken into account, so you must specify the full pathname to the command, and shell builtin commands will not work. For instance, on Unix the above three examples might look like:
  1. SysExec.exec("/usr/ucb/lpr Some-File");
  2.         SysExec.execWait("/usr/local/bin/javac Foo.java");
            SysExec.execWait("/usr/local/bin/java Foo");
            
  3. SysExec.execPrint("/usr/bin/ls -al");

Version:
$Id: SysExec.java,v 1.2 2005/06/22 19:13:02 hansjhaase Exp $
Author:
Marty Hall (hall@apl.jhu.edu), hansjhaase - adopted to SEHR system (hans-joerg.haase@rzbd.haw-hamburg.de)

Constructor Summary
SysExec()
           
 
Method Summary
static boolean exec(java.lang.String command)
          Starts a process to execute the command.
static boolean execPrint(java.lang.String command)
          Starts a process to execute the command.
static boolean execWait(java.lang.String command)
          Starts a process to execute the command.
static boolean getVerbose()
          Let Exec print status messages
static void main(java.lang.String[] args)
           
static void setVerbose(boolean verboseFlag)
          Determines if the Exec class should print which commands are being executed, and print error messages if a problem is found.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SysExec

public SysExec()
Method Detail

setVerbose

public static void setVerbose(boolean verboseFlag)
Determines if the Exec class should print which commands are being executed, and print error messages if a problem is found. Default is true.

Parameters:
verboseFlag - true: print, false: don't print

getVerbose

public static boolean getVerbose()
Let Exec print status messages


exec

public static boolean exec(java.lang.String command)
Starts a process to execute the command. Returns immediately, even if the new process is still running.

Parameters:
command - The full pathname of the command to be executed. No shell builtins (e.g. "cd") or shell meta-chars (e.g. ">") allowed.
Returns:
false if a problem is known to occur, but since this returns immediately, problems aren't usually found in time. Returns true otherwise.

execWait

public static boolean execWait(java.lang.String command)
Starts a process to execute the command. Waits for the process to finish before returning.

Parameters:
command - The full pathname of the command to be executed. No shell builtins or shell meta-chars allowed.
Returns:
false if a problem is known to occur, either due to an exception or from the subprocess returning a non-zero value. Returns true otherwise.

execPrint

public static boolean execPrint(java.lang.String command)
Starts a process to execute the command. Prints all output the command gives.

Parameters:
command - The full pathname of the command to be executed. No shell builtins or shell meta-chars allowed.
Returns:
false if a problem is known to occur, either due to an exception or from the subprocess returning a non-zero value. Returns true otherwise.

main

public static void main(java.lang.String[] args)