Long-Running Commands

If you want to execute long-running commands (such as daemons), it may not be practical to execute the command directly. Because the specified command must terminate before control is passed to the next activity, the process instance must run until the external command completes. To avoid this problem, you may want to create a script that runs the desired commands in the background.

The syntax of executing commands as background processes differs by operating system. For example, on UNIX, to run a command in the background, you append the ampersand character (&) to the command. On Microsoft Windows, you use the START command in a batch file to run a command in a different process.

After creating a script to run commands in the background, specify the script as the command to run in the External Command activity. The script runs the desired command and returns the process ID of the process it started. The return code of the script is stored in the returnCode item of the External Command activity’s output.

If you want to start a long-running command in the background and then later terminate the background process, you should store the process ID returned by the script in a file or database table. Another process instance can then read the process ID and kill the process with the appropriate operating system command when necessary.