Add helper to get exit status of command

This commit is contained in:
Andrew Ayer
2015-02-07 12:43:17 -08:00
parent c850d65242
commit fc583c7d4f
3 changed files with 6 additions and 5 deletions

View File

@@ -273,9 +273,9 @@ int exec_command_with_input (const std::vector<std::string>& command, const char
return status;
}
bool successful_exit (int status)
int exit_status (int wait_status)
{
return status != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0;
return wait_status != -1 && WIFEXITED(wait_status) ? WEXITSTATUS(wait_status) : -1;
}
void touch_file (const std::string& filename)

View File

@@ -316,9 +316,9 @@ int exec_command_with_input (const std::vector<std::string>& command, const char
return exit_code;
}
bool successful_exit (int status)
int exit_status (int status)
{
return status == 0;
return status;
}
void touch_file (const std::string& filename)

View File

@@ -63,7 +63,8 @@ std::string our_exe_path ();
int exec_command (const std::vector<std::string>&);
int exec_command (const std::vector<std::string>&, std::ostream& output);
int exec_command_with_input (const std::vector<std::string>&, const char* p, size_t len);
bool successful_exit (int status);
int exit_status (int wait_status); // returns -1 if process did not exit (but was signaled, etc.)
inline bool successful_exit (int wait_status) { return exit_status(wait_status) == 0; }
void touch_file (const std::string&);
void remove_file (const std::string&);
std::string escape_shell_arg (const std::string&);