edu.stanford.nlp.util
Class SystemUtils

java.lang.Object
  extended by edu.stanford.nlp.util.SystemUtils

public class SystemUtils
extends Object

Useful methods for running shell commands, getting the process ID, checking memory usage, etc.

Author:
Bill MacCartney, Steven Bethard (run(java.lang.ProcessBuilder))

Nested Class Summary
static class SystemUtils.ProcessException
          Runtime exception thrown by execute.
static class SystemUtils.ProcessOutputStream
          Helper class that acts as a output stream to a process
 
Constructor Summary
SystemUtils()
           
 
Method Summary
static int getMemoryInUse()
          Returns the number of megabytes (MB) of memory in use.
static int getPID()
          Returns the process ID, via an awful hack.
static int getPIDNoExceptions()
          Returns the process ID, via an awful hack, or else -1.
static void main(String[] args)
           
static void run(ProcessBuilder builder)
          Start the process defined by the ProcessBuilder, and run until complete.
static void run(ProcessBuilder builder, Writer output, Writer error)
          Start the process defined by the ProcessBuilder, and run until complete.
static void runShellCommand(String cmd)
          Runs the shell command which is specified, along with its arguments, in the given String.
static void runShellCommand(String[] cmd)
          Runs the shell command which is specified, along with its arguments, in the given String array.
static void runShellCommand(String[] cmd, StringBuilder outputLines)
          Runs the shell command which is specified, along with its arguments, in the given String array.
static void runShellCommand(String[] cmd, StringBuilder outputLines, StringBuilder errorLines)
          Runs the shell command which is specified, along with its arguments, in the given String array.
static void runShellCommand(String cmd, StringBuilder outputLines)
          Runs the shell command which is specified, along with its arguments, in the given String.
static void runShellCommand(String cmd, StringBuilder outputLines, StringBuilder errorLines)
          Runs the shell command which is specified, along with its arguments, in the given String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SystemUtils

public SystemUtils()
Method Detail

run

public static void run(ProcessBuilder builder)
Start the process defined by the ProcessBuilder, and run until complete. Process output and errors will be written to System.out and System.err, respectively.

Parameters:
builder - The ProcessBuilder defining the process to run.

run

public static void run(ProcessBuilder builder,
                       Writer output,
                       Writer error)
Start the process defined by the ProcessBuilder, and run until complete.

Parameters:
builder - The ProcessBuilder defining the process to run.
output - Where the process output should be written. If null, the process output will be written to System.out.
error - Where the process error output should be written. If null, the process error output will written to System.err.

runShellCommand

public static void runShellCommand(String[] cmd,
                                   StringBuilder outputLines,
                                   StringBuilder errorLines)
                            throws IOException
Runs the shell command which is specified, along with its arguments, in the given String array. If there is any regular output or error output, it is appended to the given StringBuilders.

Throws:
IOException

runShellCommand

public static void runShellCommand(String cmd,
                                   StringBuilder outputLines,
                                   StringBuilder errorLines)
                            throws IOException
Runs the shell command which is specified, along with its arguments, in the given String. If there is any regular output or error output, it is appended to the given StringBuilders.

Throws:
IOException

runShellCommand

public static void runShellCommand(String[] cmd,
                                   StringBuilder outputLines)
                            throws IOException
Runs the shell command which is specified, along with its arguments, in the given String array. If there is any regular output, it is appended to the given StringBuilder. If there is any error output, it is swallowed (!).

Throws:
IOException

runShellCommand

public static void runShellCommand(String cmd,
                                   StringBuilder outputLines)
                            throws IOException
Runs the shell command which is specified, along with its arguments, in the given String. If there is any regular output, it is appended to the given StringBuilder. If there is any error output, it is swallowed (!).

Throws:
IOException

runShellCommand

public static void runShellCommand(String[] cmd)
                            throws IOException
Runs the shell command which is specified, along with its arguments, in the given String array. If there is any output, it is swallowed (!).

Throws:
IOException

runShellCommand

public static void runShellCommand(String cmd)
                            throws IOException
Runs the shell command which is specified, along with its arguments, in the given String. If there is any output, it is swallowed (!).

Throws:
IOException

getPID

public static int getPID()
                  throws IOException
Returns the process ID, via an awful hack.

Throws:
IOException

getPIDNoExceptions

public static int getPIDNoExceptions()
Returns the process ID, via an awful hack, or else -1.


getMemoryInUse

public static int getMemoryInUse()
Returns the number of megabytes (MB) of memory in use.


main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Stanford NLP Group