Synopsis
This operator simply executes a command in a shell of the underlying operating system, basically any system command or external program.
Description
This operator executes a system command. The command and all its arguments are specified by the parameter command
. The standard output stream and the error stream of the process can be redirected to the logfile.
Please note also that the command is system dependent. Characters that have special meaning on the shell like e.g. the pipe symbol or brackets and braces do not have a special meaning to Java.
The method Runtime.exec(String)
is used to execute the command. Please note, that this (Java) method parses the string into tokens before it is executed. These tokens are not interpreted by a shell (which?). If the desired command involves piping, redirection or other shell features, it is best to create a small shell script to handle this.
<p>
A hint for Windows / MS DOS users: simple commands should be preceeded by cmd /c call
, eg. cmd /c notepad
or just notepad
in case you are executing a program and not just a shell command. Then Windows opens a new shell, executes the command, and closes the shell again. However, Windows 7 does not open a new shell, it just executes the command.
<p>
Another option would be to preceed the command with cmd /c start
which opens the shell and keeps it open. The rest process will not be executed until the shell is closed by the user.
Input
- through 1:
Output
- through 1:
Parameters
- command: Command to execute.
- log stdout: If set to true, the stdout stream of the command is redirected to the logfile.
- log stderr: If set to true, the stderr stream of the command is redirected to the logfile.