From ae297e4405dc99becb7e580345f8bc55efb84804 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 16 Jan 2024 13:56:10 +0000 Subject: [PATCH] HackStudio: Use Core::Process API to run template post-create programs --- .../DevTools/HackStudio/ProjectTemplate.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Userland/DevTools/HackStudio/ProjectTemplate.cpp b/Userland/DevTools/HackStudio/ProjectTemplate.cpp index 5a8466a6df..b703fd4937 100644 --- a/Userland/DevTools/HackStudio/ProjectTemplate.cpp +++ b/Userland/DevTools/HackStudio/ProjectTemplate.cpp @@ -11,10 +11,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -92,17 +92,14 @@ ErrorOr ProjectTemplate::create_project(ByteString const& name, ByteString // Generate a namespace-safe project name (replace hyphens with underscores) auto namespace_safe = name.replace("-"sv, "_"sv, ReplaceMode::All); - - char const* argv[] = { postcreate_script_path.characters(), name.characters(), path.characters(), namespace_safe.characters(), nullptr }; - - pid_t child_pid = TRY(Core::System::posix_spawn(postcreate_script_path, nullptr, nullptr, const_cast(argv), environ)); + auto child_process = TRY(Core::Process::spawn({ + .executable = postcreate_script_path, + .arguments = { name, path, namespace_safe }, + })); // Command spawned, wait for exit. - auto waitpid_result = TRY(Core::System::waitpid(child_pid, 0)); - int child_error = WEXITSTATUS(waitpid_result.status); - dbgln("Post-create script exited with code {}", child_error); - - if (child_error != 0) + auto child_exited_with_0 = TRY(child_process.wait_for_termination()); + if (!child_exited_with_0) return Error::from_string_literal("Project post-creation script exited with non-zero error code."); }