The Shell
class is a wrapper for ShellStream
that aims at more regular shell tasks. This class works synchronously and makes general shell tasks more easy than ShellStream
.
Shell shell = new Shell();
Command command = shell.execute("some command", 0);
if (command.getResultSuccess()) {
// Handle command output
}
shell.destroy();
The Shell
class does not really deal with strings, but instead with a Command class that acts as both input and output container. But it has convenient methods that automaticaly creates a Command
with the parsed string and populates it with shell output.
Shell shell = new Shell();
Command command = new Command("some command", 0);
shell.execute(command);
if (command.getResultSuccess()) {
// Handle command output
}
shell.destroy();
As mentioned above, the Shell
class is a wrapper for ShellStream
, which means that you can reuse any existing connections with Shell
.
ShellStream stream = new ShellStream();
Shell shell = new Shell(stream); // Add existing ShellStream
Command command = new Command("some command", 0);
shell.execute(command);
if (command.getResultSuccess()) {
// Handle command output
}
shell.close(); // Do not destroy
Note the last line compared to the other examples. We replaced
destroy()
withclose()
. The first method will not only close theShell
class, but also destroy the wrappedShellStream
. If we want to keep use our connection for other things, we can instead useclose()
which will only cleanup theShell
class, but not touch theShellStream
within.