diff --git a/Userland/Utilities/pls.cpp b/Userland/Utilities/pls.cpp index 0b6c231b14f..7ada606c757 100644 --- a/Userland/Utilities/pls.cpp +++ b/Userland/Utilities/pls.cpp @@ -10,12 +10,11 @@ #include #include #include -#include #include ErrorOr serenity_main(Main::Arguments arguments) { - Vector command; + Vector command; Core::ArgsParser args_parser; uid_t as_user_uid = 0; args_parser.set_stop_on_first_non_option(true); @@ -46,23 +45,18 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath exec")); - Vector exec_arguments; - for (auto const& arg : command) - exec_arguments.append(arg); - exec_arguments.append(nullptr); - - Vector environment_strings; - if (auto* term = getenv("TERM")) - environment_strings.append(String::formatted("TERM={}", term)); - - Vector exec_environment; - for (auto& item : environment_strings) - exec_environment.append(item.characters()); - exec_environment.append(nullptr); - - if (execvpe(command.at(0), const_cast(exec_arguments.data()), const_cast(exec_environment.data())) < 0) { - perror("execvpe"); - exit(1); + Vector exec_environment_strings; + Vector exec_environment; + if (auto* term = getenv("TERM")) { + exec_environment_strings.append(String::formatted("TERM={}", term)); + exec_environment.append(exec_environment_strings.last()); } + + Vector exec_arguments; + exec_arguments.ensure_capacity(command.size()); + for (auto const& it : command) + exec_arguments.append(it.to_string()); + + TRY(Core::System::exec(command.at(0), command, Core::System::SearchInPath::Yes, exec_environment)); return 0; }