Gio.Subprocess.prototype.communicate
function communicate(stdin_buf: ByteArray, cancellable: Gio.Cancellable): [ok: Boolean, stdout_buf: ByteArray, stderr_buf: ByteArray] {
// Gjs wrapper for g_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 Gio.SubprocessFlags.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 Gio.SubprocessFlags.stdout_pipe or Gio.SubprocessFlags.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 Gio.SubprocessFlags.stdout_pipe, stdout_buf will contain the data read from stdout. Otherwise, for subprocesses not created with Gio.SubprocessFlags.stdout_pipe, stdout_buf will be set to null. Similar provisions apply to stderr_buf and Gio.SubprocessFlags.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 Gio.SubprocessFlags.stdout_pipe and Gio.SubprocessFlags.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: Gio.Subprocess.prototype.get_if_exited, Gio.Subprocess.prototype.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).
Since 2.40
- stdin_buf
data to send to the stdin of the subprocess, or null
- cancellable
- ok
true if successful
- stdout_buf
data read from the subprocess stdout
- stderr_buf
data read from the subprocess stderr