base.Channel.openPipe

Opens a pipe channel to a subprocess.

Syntax

openPipe(
   command STRING,
   mode STRING )
  1. command is the system command to be executed.
  2. mode is the open mode. Can be "r", "w", "a" or "u" (combined with "b" if needed).

Usage

With the openPipe() method, you can read from the standard output of a subprocess, write to the standard input, or both.

Important: This feature is not supported on mobile platforms.
The opening mode can be one of the following:
  • r: For read only from standard output of the command.
  • w: For write only to standard input of the command.
  • a: For write only to standard input of the command.
  • u: For read from standard output and write to standard input of the command.
Any of these modes can be followed by b, to use binary mode and avoid CR/LF translation on Windows® platforms.
Note: The binary mode is only required in specific cases, and will only take effect when writing data.

If the opening mode is not one of the above letters, the method will raise error -8085.

Some commands like the Unix tr command buffer the stdout stream. This may block the readLine() calls, when using the openPipe() method with "u" option, and writing to stdin / reading from stdout line by line. To avoid readLine() to block in such case, you must force the command to flush each line written to stdout, for example with the stdbuf -oL command.

Example

CALL ch.openPipe( "ls", "r" ) 

For a complete example, see Example 2: Executing UNIX commands.