/* * Copyright (c) 2020, Itamar S. * Copyright (c) 2022, David Tuin * Copyright (c) 2023, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Core { // FIXME: Unify this and the below 'command' functions with Command class below struct CommandResult { int exit_code { 0 }; ByteBuffer output; ByteBuffer error; }; ErrorOr command(ByteString const& program, Vector const& arguments, Optional chdir); ErrorOr command(ByteString const& command_string, Optional chdir); class Command { public: struct ProcessOutputs { ByteBuffer standard_output; ByteBuffer standard_error; }; static ErrorOr> create(StringView command, char const* const arguments[]); Command(pid_t pid, NonnullOwnPtr stdin_file, NonnullOwnPtr stdout_file, NonnullOwnPtr stderr_file); ErrorOr write(StringView input); ErrorOr write_lines(Span lines); ErrorOr read_all(); enum class ProcessResult { Running, DoneWithZeroExitCode, Failed, FailedFromTimeout, Unknown, }; ErrorOr status(int options = 0); private: pid_t m_pid { -1 }; NonnullOwnPtr m_stdin; NonnullOwnPtr m_stdout; NonnullOwnPtr m_stderr; }; }