|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jApp.jdic.Shell
public class Shell
Implements a simple wrapper around the RunTime.exec() method that allows easy capture of command results (that is 'stdout' and 'stderr' and feeding the command via 'stdin'.
Constructor Summary | |
---|---|
Shell()
|
Method Summary | |
---|---|
java.lang.String |
execute(java.lang.String cmd,
java.lang.String input)
Executes a given command line with default time out of five seconds. |
java.lang.String |
execute(java.lang.String cmd,
java.lang.String input,
int timeout)
Executes a given command line, aborting after given timeout. |
java.lang.String |
getCommand()
Gets the last command that has been executed (succesfully or not in other word the command line that returned the exit code you can query with getExitCode() |
java.lang.Exception |
getException()
Gets the exception that was thrown during, before or after the execution of the command line within the execute method, if any. |
int |
getExitCode()
Gets the exit code from the last command executed, should be checked after each invokation of execute to verify success. |
java.lang.String |
sudoExecute(java.lang.String cmd,
java.lang.String input,
java.lang.String password)
Executes a given command line with root rights and default time out of five seconds. |
java.lang.String |
sudoExecute(java.lang.String cmd,
java.lang.String input,
java.lang.String password,
int timeout)
Executes a given command line with root rights. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Shell()
Method Detail |
---|
public java.lang.String sudoExecute(java.lang.String cmd, java.lang.String input, java.lang.String password) throws java.lang.Exception
cmd
- the command line to executeinput
- the input to feed to the command via 'stdin', can be null
java.lang.Exception
execute(String, String,int)
public java.lang.String sudoExecute(java.lang.String cmd, java.lang.String input, java.lang.String password, int timeout) throws java.lang.Exception
cmd
- the command line to executeinput
- the input to feed to the command via 'stdin', can be nulltimeout
- in milliseconds after which the process is aborted, use zero for no timeout
java.lang.Exception
execute(String, String,int)
public java.lang.String execute(java.lang.String cmd, java.lang.String input)
cmd
- the command line to executeinput
- the input to feed to the command via 'stdin', can be null
execute(String, String,int)
public java.lang.String execute(java.lang.String cmd, java.lang.String input, int timeout)
getExitCode()
returns -1 and you can get the exception with the getException()
call
cmd
- the command line to executeinput
- the input to feed to the command via 'stdin', can be nulltimeout
- in milliseconds after which the process is aborted, use zero for no timeout
getExitCode()
,
getCommand()
,
getException()
public int getExitCode()
execute
to verify success. Typically 0 value indicates success,
no Unix/Linux script/program should not be able to return a code outside 0..255,
a return code of -1 indicates an exception in attempting to execute the command line
in other words an exception was thrown before or during execution of the command
and it was not possible to capture the actual exit code from the command.
public java.lang.String getCommand()
public java.lang.Exception getException()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |