com.mucommander.process
Class ProcessRunner

java.lang.Object
  extended by com.mucommander.process.ProcessRunner

public class ProcessRunner
extends java.lang.Object

Used to run process in as safe a manner as possible.

The Java process API, while very simple, contains a lot of pitfalls and requires some work to use properly. Typical errors are forgetting to monitor a process' output streams, which will make it deadlock more often than not.

Using the ProcessRunner will take care of all these tasks, while still allowing most of the flexibility of the standard API.

Author:
Nicolas Rinaudo

Method Summary
static AbstractProcess execute(java.lang.String command)
          Executes the specified command in the VM's current directory.
static AbstractProcess execute(java.lang.String[] tokens)
          Executes the specified command in the VM's current directory.
static AbstractProcess execute(java.lang.String[] tokens, AbstractFile currentDirectory)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String[] tokens, AbstractFile currentDirectory, ProcessListener listener)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String[] tokens, AbstractFile currentDirectory, ProcessListener listener, java.lang.String encoding)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String[] tokens, AbstractFile currentDirectory, java.lang.String encoding)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String[] tokens, ProcessListener listener)
          Executes the specified command in the VM's current directory.
static AbstractProcess execute(java.lang.String[] tokens, ProcessListener listener, java.lang.String encoding)
          Executes the specified command in the VM's current directory.
static AbstractProcess execute(java.lang.String[] tokens, java.lang.String encoding)
          Executes the specified command in the VM's current directory.
static AbstractProcess execute(java.lang.String command, AbstractFile currentDirectory)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String command, AbstractFile currentDirectory, ProcessListener listener)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String command, AbstractFile currentDirectory, ProcessListener listener, java.lang.String encoding)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String command, AbstractFile currentDirectory, java.lang.String encoding)
          Executes the specified command in the specified directory.
static AbstractProcess execute(java.lang.String command, ProcessListener listener)
          Executes the specified command in the VM's current directory.
static AbstractProcess execute(java.lang.String command, ProcessListener listener, java.lang.String encoding)
          Executes the specified command in the VM's current directory.
static AbstractProcess execute(java.lang.String command, java.lang.String encoding)
          Executes the specified command in the VM's current directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

execute

public static AbstractProcess execute(java.lang.String[] tokens,
                                      AbstractFile currentDirectory,
                                      ProcessListener listener,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the specified directory.

Note that both currentDirectory and listener can be set to null.
If no current directory is specified, the VM's current directory will be used. Moreover, if the current directory is not on a file system that supports process running, the user's home directory will be used instead.
If listener is set to null, nobody will be notified of the process' state. Its streams will still be emptied to prevent deadlocks.

Parameters:
tokens - tokens that compose the command to execute.
currentDirectory - directory in which to execute the process (user directory if null).
listener - object that will be notified of modifications in the process' state (ignored if null).
encoding - encoding used to read from the process' stream (system default is used if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if any error occurs while creating the process.

execute

public static AbstractProcess execute(java.lang.String command,
                                      AbstractFile currentDirectory,
                                      ProcessListener listener)
                               throws java.io.IOException
Executes the specified command in the specified directory.

This is a convenience method and behaves exactly as a call to execute(command, currentDirectory, listener, null).

Parameters:
command - command to execute.
currentDirectory - directory in which to execute the process (user directory if null).
listener - object that will be notified of modifications in the process' state (ignored if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if any error occurs while creating the process.

execute

public static AbstractProcess execute(java.lang.String command)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(command, null, null, null).

Parameters:
command - command to execute.
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String,AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String command,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(command, null, null, encoding).

Parameters:
command - command to execute.
encoding - encoding used to read from the process' stream (system default is used if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String,AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String command,
                                      ProcessListener listener)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(command, null, listener, null).

Parameters:
command - command to execute.
listener - object that will be notified of any modification in the process' state (ignored if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String,AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String command,
                                      ProcessListener listener,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(command, null, listener, encoding).

Parameters:
command - command to execute.
listener - object that will be notified of any modification in the process' state.
encoding - encoding used to read from the process' stream (system default is used if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String,AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String command,
                                      AbstractFile currentDirectory)
                               throws java.io.IOException
Executes the specified command in the specified directory.

This is a convenience method and behaves exactly as a call to execute(command, currentDirectory, null, null).

Parameters:
command - command to execute.
currentDirectory - directory in which to run the command.
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String,AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String command,
                                      AbstractFile currentDirectory,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the specified directory.

This is a convenience method and behaves exactly as a call to execute(command, currentDirectory, null, encoding).

Parameters:
command - command to execute.
currentDirectory - directory in which to run the command (uses the VM's current directory if null).
encoding - encoding used to read from the process' stream (system default is used if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String,AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String command,
                                      AbstractFile currentDirectory,
                                      ProcessListener listener,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the specified directory.

This is a convenience method and behaves exactly as a call to execute(tokens, currentDirectory, null, encoding) where tokens is an array contains all the tokens found in command.

More precisely, the command string is broken into tokens using a StringTokenizer created by the call new StringTokenizer(command) with no further modification of the character categories. The tokens produced by the tokenizer are then placed in the new string array tokens, in the same order.

Parameters:
command - command to execute.
currentDirectory - directory in which to run the command (uses the VM's current directory if null).
encoding - encoding used to read from the process' stream (system default is used if null).
listener - object that will be notified of modifications in the process' state (ignored if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.

execute

public static AbstractProcess execute(java.lang.String[] tokens,
                                      AbstractFile currentDirectory,
                                      ProcessListener listener)
                               throws java.io.IOException
Executes the specified command in the specified directory.

This is a convenience method and behaves exactly as a call to execute(tokens, currentDirectory, listener, null).

Parameters:
tokens - command to execute.
currentDirectory - directory in which to run the command (uses the VM's current directory if null).
listener - object that will be notified of any modification in the process' state.
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.

execute

public static AbstractProcess execute(java.lang.String[] tokens)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(tokens, null, null, null).

Parameters:
tokens - command to execute.
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.

execute

public static AbstractProcess execute(java.lang.String[] tokens,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(tokens, null, null, encoding).

Parameters:
tokens - command to execute.
encoding - encoding used to read from the process' stream (system default is used if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.

execute

public static AbstractProcess execute(java.lang.String[] tokens,
                                      ProcessListener listener)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(tokens, null, listener, null).

Parameters:
tokens - command to execute.
listener - object that will be notified of any modification in the process' state (ignored if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String[],AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String[] tokens,
                                      ProcessListener listener,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the VM's current directory.

This is a convenience method and behaves exactly as a call to execute(tokens, null, listener, encoding).

Parameters:
tokens - command to execute.
listener - object that will be notified of any modification in the process' state (ignored if null).
encoding - encoding used to read from the process' stream (system default is used if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String[],AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String[] tokens,
                                      AbstractFile currentDirectory)
                               throws java.io.IOException
Executes the specified command in the specified directory.

This is a convenience method and behaves exactly as a call to execute(tokens, currentDirectory, null, null).

Parameters:
tokens - command to execute.
currentDirectory - directory in which to run the command.
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String[],AbstractFile,ProcessListener,String)

execute

public static AbstractProcess execute(java.lang.String[] tokens,
                                      AbstractFile currentDirectory,
                                      java.lang.String encoding)
                               throws java.io.IOException
Executes the specified command in the specified directory.

This is a convenience method and behaves exactly as a call to execute(tokens, currentDirectory, null, null).

Parameters:
tokens - command to execute.
currentDirectory - directory in which to run the command.
encoding - encoding used to read from the process' stream (system default is used if null).
Returns:
the generated process.
Throws:
java.io.IOException - thrown if an error happens while starting the process.
See Also:
execute(String[],AbstractFile,ProcessListener,String)


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard