utils: rework running system commands

Use g_spawn and pass arguments, so we don't involve a shell that needs
escaping etc.

Improve error handling.
This commit is contained in:
Dirk-Jan C. Binnema
2023-07-18 19:10:08 +03:00
parent 5efd0a61aa
commit cf6c5a36d7
4 changed files with 56 additions and 30 deletions

View File

@ -196,6 +196,22 @@ Result<std::string> make_temp_dir();
Result<void> remove_directory(const std::string& path);
/**
* Run some system command
*
* @param cmd the command
*
* @return Ok(exit code) or an error. Note that exit-code != 0 is _not_
* considered an error from the perspective of this function.
*/
struct CommandOutput {
int exit_code;
std::string standard_out;
std::string standard_err;
};
Result<CommandOutput> run_command(std::initializer_list<std::string> args);
} // namespace Mu
#endif /* MU_UTILS_FILE_HH__ */