Home
Ratchet Library :: API Reference
API  ·  Manual

Module ratchet.exec

The exec library provides relatively powerful command execution in an event-based manner. Commands run with these functions will be run in a separate OS process using a fork-exec.

Functions

communicate (self, data) Starts the command process.
get_argv (self) Returns the table array of arguments that the exec object was created with.
get_start_time (self) Returns the UNIX timestamp when the process command process was started, that is, when the start() method was called.
kill (self, signal) Sends a signal to the command process.
new (argv) Creates a new execution object, running the command stored in table argv.
start (self) Starts the command process.
stderr (self) Returns the standard error file, which has its own methods close() and read().
stdin (self) Returns the standard input file, which has its own methods close() and write().
stdout (self) Returns the standard output file, which has its own methods close() and read().
wait (self, timeout) Waits for the command process to terminate.


Functions

communicate (self, data)
Starts the command process. After writing optional data, stdin is closed. Reads data from stdout and stderr until both are closed. Finally, calls wait() to finish the command process. Functions similarly to the Popen.communicate() method of the subprocess module in Python.

Parameters

  • self: the exec object.
  • data: optional data to write to stdin before closing it.

Return value:

The concatenations of stdout and stderr, respectively, followed by the exit status.
get_argv (self)
Returns the table array of arguments that the exec object was created with.

Parameters

  • self: the exec object.

Return value:

an argv table array.
get_start_time (self)
Returns the UNIX timestamp when the process command process was started, that is, when the start() method was called.

Parameters

  • self: the exec object.

Return value:

timestamp when the process was started, or nil if unstarted.
kill (self, signal)
Sends a signal to the command process.

Parameters

  • self: the exec object.
  • signal: The signal number of name (see signal(7)), defaulting to "SIGTERM".
new (argv)
Creates a new execution object, running the command stored in table argv. The object returned by this command is not running until you call its start() method.

Parameters

  • argv: Table array of command arguments, starting with the command itself.

Return value:

a new exec object.
start (self)
Starts the command process. No other methods may be called before this one.

Parameters

  • self: the exec object.

Return value:

the operating system PID of the new process.
stderr (self)
Returns the standard error file, which has its own methods close() and read(). Data written to the command process's standard error will be returned by this object's read() method.

Parameters

  • self: the exec object.

Return value:

the process's standard error file object.
stdin (self)
Returns the standard input file, which has its own methods close() and write(). Data written with write() will show up in the command process's standard input.

Parameters

  • self: the exec object.

Return value:

the process's standard input file object.
stdout (self)
Returns the standard output file, which has its own methods close() and read(). Data written to the command process's standard output will be returned by this object's read() method.

Parameters

  • self: the exec object.

Return value:

the process's standard output file object.
wait (self, timeout)
Waits for the command process to terminate.

Parameters

  • self: the exec object.
  • timeout: number of seconds to wait (fractions are ok), default forever.

Return value:

The exit status integer.