communicate
Description:
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 throws 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 throws) 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: get_if_exited, get_exit_status) 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:
this | |
stdin_buf |
data to send to the stdin of the subprocess, or null |
cancellable | |
stdout_buf |
data read from the subprocess stdout |
stderr_buf |
data read from the subprocess stderr |
Returns:
true if successful |