Subprocess
- launch and manage subprocesses
package require Subprocess
set p [Subprocess::Popen #auto cmd]
set rval [$p wait]
::itcl::delete object $p
The Popen
class takes the pain out of executing subprocesses with Tcl's
open
command. You can launch a process, monitor its status and redirect its
standard input and output streams to alternative Tcl channels. By using pipes,
you may even communicate with the process directly, even though you might
prefer to use the CliDriver
(3caius) module in that case.
constructor
?-stdout
chan? ?-stderr
chan? ?-stdin
chan? ?-timeout
ms?Launch a subprocess and optionally redirect its standard input and output streams to alternative Tcl channels. If a timeout is specified, the process will be forcefully terminated when it exceeds the timeout. Raises a `Subprocess::Error` if invocation fails for some reason.
method kill
Kill the subprocess. On Unix this is equivalent to sending a SIGKILL.
method pid
Return the process ID of the subprocess.
method process_exists
Check if the process is still alive.
method timeout_occurred
Check if a timeout occurred.
method terminate
Terminate the subprocess. On Unix this is equivalent to sending a SIGTERM.
method wait
Wait on the subprocess to end and return its exit code.
Deleting a Popen
object that is associated with an active process, using
itcl::delete object
, will implicitely terminate the process. If the process
was terminated pre-maturely, wait will return -1.
Channel descriptors passed as parameters to the Popen
command are
effectively moved to another thread and are hence-forth not accessible anymore
in the calling thread. This does not apply to the standard channels stdout,
stderr and stdin. They keep functioning as expected.
error
(3caius), signal
(7)