Subprocess.communicate

bool communicate(glib.bytes.Bytes stdinBuf, gio.cancellable.Cancellable cancellable, out glib.bytes.Bytes stdoutBuf, out glib.bytes.Bytes stderrBuf)

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 [gio.types.SubprocessFlags.StdinPipe]. 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 [gio.types.SubprocessFlags.StdoutPipe] or [gio.types.SubprocessFlags.StderrPipe] 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 [gio.types.SubprocessFlags.StdoutPipe], stdout_buf will contain the data read from stdout. Otherwise, for subprocesses not created with [gio.types.SubprocessFlags.StdoutPipe], stdout_buf will be set to null. Similar provisions apply to stderr_buf and [gio.types.SubprocessFlags.StderrPipe].

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 [gio.types.SubprocessFlags.StdoutPipe] and [gio.types.SubprocessFlags.StderrMerge]. 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: [gio.subprocess.Subprocess.getIfExited], [gio.subprocess.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).

Parameters

stdinBufdata to send to the stdin of the subprocess, or null
cancellablea #GCancellable
stdoutBufdata read from the subprocess stdout
stderrBufdata read from the subprocess stderr

Returns

true if successful

Throws

[ErrorWrap]