1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:07:45 +00:00

Run: Use Core::Process::spawn() to launch commands

This commit is contained in:
MacDue 2023-03-15 16:59:31 +00:00 committed by Linus Groh
parent 43529ea25e
commit 3feddbf9da

View file

@ -9,6 +9,7 @@
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/URL.h> #include <AK/URL.h>
#include <Applications/Run/RunGML.h> #include <Applications/Run/RunGML.h>
#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h> #include <LibCore/StandardPaths.h>
#include <LibDesktop/Launcher.h> #include <LibDesktop/Launcher.h>
#include <LibFileSystem/FileSystem.h> #include <LibFileSystem/FileSystem.h>
@ -110,14 +111,12 @@ void RunWindow::do_run()
bool RunWindow::run_as_command(DeprecatedString const& run_input) bool RunWindow::run_as_command(DeprecatedString const& run_input)
{ {
pid_t child_pid; // TODO: Query and use the user's preferred shell.
char const* shell_executable = "/bin/Shell"; // TODO query and use the user's preferred shell. auto maybe_child_pid = Core::Process::spawn("/bin/Shell"sv, Array { "-c", run_input.characters() }, {}, Core::Process::KeepAsChild::Yes);
char const* argv[] = { shell_executable, "-c", run_input.characters(), nullptr }; if (maybe_child_pid.is_error())
if ((errno = posix_spawn(&child_pid, shell_executable, nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
return false; return false;
}
pid_t child_pid = maybe_child_pid.release_value();
// Command spawned in child shell. Hide and wait for exit code. // Command spawned in child shell. Hide and wait for exit code.
int status; int status;