java.lang.Object
net.i2p.util.ShellCommand
Passes a command to the OS shell for execution and manages the input and output.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classExecutes a shell command in its own thread.private static classHolds the result of a shell command.private static classConsumes stream data.Constructor Summary
ConstructorsConstructorDescriptionNo command is running; each execute* call starts its own CommandThread and waits for it, so nothing is pending at construction.Method Summary
Modifier and TypeMethodDescriptionprivate booleanExecutes the command with an explicit environment and waits for it to complete.private booleanexecuteSAWT(Object shellCommand, String[] envp, int seconds) Execute the command, timing it for the debug log.booleanexecuteSilentAndWait(String[] commandArray) Passes a command to the shell for execution.booleanexecuteSilentAndWaitTimed(String[] commandArray, int seconds) Passes a command to the shell for execution.booleanexecuteSilentAndWaitTimed(String[] commandArray, String[] envp, int seconds) Execute the command array with an explicit environment, waiting for completion with a timeout, e.g.booleanexecuteSilentAndWaitTimed(String shellCommand, int seconds) Passes a command to the shell for execution.static voidJust does exec, this is NOT a test of ShellCommand.
Constructor Details
ShellCommand
public ShellCommand()No command is running; each execute* call starts its own CommandThread and waits for it, so nothing is pending at construction.
Method Details
executeSilentAndWait
Passes a command to the shell for execution. This method blocks until all of the command's resulting shell processes have completed. Any output produced by the executed command will not be displayed.- Parameters:
commandArray- The command for the shell to execute, as a String[]. SeeRuntime.exec(String[]) for more info.- Returns:
trueif the spawned shell process returns an exit status of 0 (indicating success), elsefalse.
executeSilentAndWaitTimed
Passes a command to the shell for execution. This method blocks until all of the command's resulting shell processes have completed unless a specified number of seconds has elapsed first. Any output produced by the executed command will not be displayed.Warning, no good way to quote or escape spaces in arguments when shellCommand is a String. Use a String array for best results, especially on Windows.
- Parameters:
shellCommand- The command for the shell to execute, as a String. You can't quote arguments successfully. SeeRuntime.exec(String) for more info.seconds- The method will returntrueif this number of seconds elapses without the process returning an exit status. A value of0here disables waiting.- Returns:
trueif the spawned shell process returns an exit status of 0 (indicating success), OR if the time expires, elsefalse.
executeSilentAndWaitTimed
Passes a command to the shell for execution. This method blocks until all of the command's resulting shell processes have completed unless a specified number of seconds has elapsed first. Any output produced by the executed command will not be displayed.- Parameters:
commandArray- The command for the shell to execute, as a String[]. SeeRuntime.exec(String[]) for more info.seconds- The method will returntrueif this number of seconds elapses without the process returning an exit status. A value of0here disables waiting.- Returns:
trueif the spawned shell process returns an exit status of 0 (indicating success), OR if the time expires, elsefalse.
executeSilentAndWaitTimed
Execute the command array with an explicit environment, waiting for completion with a timeout, e.g. to hand a password to keytool via-storepass:envinstead of the visible command line.- Parameters:
commandArray- the command and its argumentsenvp- environment entries as NAME=value strings, replacing the inherited environment (include those entries you want to keep), or null to inherit itseconds- the maximum time to wait, in seconds- Returns:
- true if the spawned process returns an exit status of 0 (indicating success), OR if the time expires, else false
executeSAWT
Execute the command, timing it for the debug log.- Parameters:
shellCommand- a command string or a String[] command arrayenvp- the environment for the command, or null to inherit the current oneseconds- how long to wait for the command to finish, 0 or less to wait forever- Returns:
- true if the command succeeded or the wait timed out, false if it failed
main
Just does exec, this is NOT a test of ShellCommand.- Parameters:
args- the command to run as an exec() argument array; ignored when empty, which prints the usage line instead
execute
Executes the command with an explicit environment and waits for it to complete. The process is destroyed if the wait is interrupted.- Parameters:
shellCommand- either a String or a String[] (since 0.8.3) - quick hackenvp- environment entries as NAME=value strings, or null to inherit- Returns:
- true if the process exited with status 0, else false