/* * Copyright (c) 2023, Andrew Kaster * * SPDX-License-Identifier: BSD-2-Clause */ #include "HelperProcess.h" #include "Utilities.h" #include #include ErrorOr spawn_helper_process(StringView process_name, ReadonlySpan arguments, Core::System::SearchInPath search_in_path, Optional> environment) { auto paths = TRY(get_paths_for_helper_process(process_name)); VERIFY(!paths.is_empty()); ErrorOr result; for (auto const& path : paths) { result = Core::System::exec(path, arguments, search_in_path, environment); if (!result.is_error()) break; } return result; } ErrorOr> get_paths_for_helper_process(StringView process_name) { Vector paths; TRY(paths.try_append(TRY(String::formatted("./{}/{}", process_name, process_name)))); TRY(paths.try_append(TRY(String::formatted("{}/{}", TRY(ak_string_from_qstring(QCoreApplication::applicationDirPath())), process_name)))); TRY(paths.try_append(TRY(String::formatted("./{}", process_name)))); // NOTE: Add platform-specific paths here return paths; }