Subprocess.communicate

Communicate with the subprocess until it terminates, and all input and output has been completed.

If stdin_buf is given, the subprocess must have been created with G_SUBPROCESS_FLAGS_STDIN_PIPE. The given data is fed to the stdin of the subprocess and the pipe is closed (ie: EOF).

At the same time (as not to cause blocking when dealing with large amounts of data), if G_SUBPROCESS_FLAGS_STDOUT_PIPE or G_SUBPROCESS_FLAGS_STDERR_PIPE were used, reads from those streams. The data that was read is returned in stdout and/or the stderr.

If the subprocess was created with G_SUBPROCESS_FLAGS_STDOUT_PIPE, stdout_buf will contain the data read from stdout. Otherwise, for subprocesses not created with G_SUBPROCESS_FLAGS_STDOUT_PIPE, stdout_buf will be set to NULL. Similar provisions apply to stderr_buf and G_SUBPROCESS_FLAGS_STDERR_PIPE.

As usual, any output variable may be given as NULL to ignore it.

If you desire the stdout and stderr data to be interleaved, create the subprocess with G_SUBPROCESS_FLAGS_STDOUT_PIPE and G_SUBPROCESS_FLAGS_STDERR_MERGE. The merged result will be returned in stdout_buf and stderr_buf will be set to NULL.

In case of any error (including cancellation), FALSE will be returned with error set. Some or all of the stdin data may have been written. Any stdout or stderr data that has been read will be discarded. None of the out variables (aside from error) will have been set to anything in particular and should not be inspected.

In the case that TRUE is returned, the subprocess has exited and the exit status inspection APIs (eg: Subprocess.getIfExited, Subprocess.getExitStatus) may be used.

You should not attempt to use any of the subprocess pipes after starting this function, since they may be left in strange states, even if the operation was cancelled. You should especially not attempt to interact with the pipes while the operation is in progress (either from another thread or if using the asynchronous version).

class Subprocess
bool
communicate

Parameters

stdinBuf Bytes

data to send to the stdin of the subprocess, or NULL

cancellable Cancellable
stdoutBuf Bytes

data read from the subprocess stdout

stderrBuf Bytes

data read from the subprocess stderr

Return Value

Type: bool

TRUE if successful

Throws

GException on failure.

Meta

Since

2.40