diff options
author | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2020-04-09 16:43:06 +0300 |
---|---|---|
committer | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2020-04-09 16:43:06 +0300 |
commit | 6a2ef269f37820db40b0d1cd19d7fdb7696c0d2a (patch) | |
tree | 9d33c76dd4ae570837dfc10793cb0849c8abc2f5 /include | |
parent | e8481260d763f8827e0188e5cd53e613aa4bd305 (diff) | |
download | libmts-6a2ef269f37820db40b0d1cd19d7fdb7696c0d2a.tar.gz libmts-6a2ef269f37820db40b0d1cd19d7fdb7696c0d2a.tar.bz2 libmts-6a2ef269f37820db40b0d1cd19d7fdb7696c0d2a.zip |
Execute system commands without invoking system shell
Changes after a code review:
- fixed documentation for the closeBackground function
- renamed ```app``` parameter to ```cmd```
Diffstat (limited to 'include')
-rw-r--r-- | include/mts/MTS_System.h | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/include/mts/MTS_System.h b/include/mts/MTS_System.h index 6bca21b..cd9b9dd 100644 --- a/include/mts/MTS_System.h +++ b/include/mts/MTS_System.h @@ -71,12 +71,12 @@ namespace MTS { * A safer alternative to System::cmd that allows to execute applications with controlled * list of arguments bypasing the system shell. * - * \param app name of the application to be executed + * \param cmd name of the application to be executed * \param argv vector of arguments (excluding argument zero) * \param result stdout output from the application is stored here * \return result code as for std::system and UNIX pclose */ - static int32_t execute(const std::string& app, const std::vector<std::string>& argv, std::string& result); + static int32_t execute(const std::string& cmd, const std::vector<std::string>& argv, std::string& result); //! Spawn a process and open pipe with the specified type (READ or WRITE) /*! @@ -84,18 +84,16 @@ namespace MTS { * list of arguments bypasing the system shell. If succeded, information about the spawned * process is written to the \p child structure. * - * \param app name of the application to be executed + * \param cmd name of the application to be executed * \param argv vector of arguments (excluding argument zero) * \param type open pipe for read from child or write to child * \return true on success, false on failure */ - static bool executeBackground(const std::string& app, const std::vector<std::string>& argv, PipeType type, ChildHandle& child); + static bool executeBackground(const std::string& cmd, const std::vector<std::string>& argv, PipeType type, ChildHandle& child); //! Close the pipe and wait for a child to finish execution /*! - * \param child name of the application to be executed - * \param argv vector of arguments (excluding argument zero) - * \param result stdout output from the application is stored here + * \param child structure with child process information as populated by executeBackground * \return result code as for std::system and UNIX pclose */ static int closeBackground(ChildHandle& child); @@ -103,13 +101,13 @@ namespace MTS { private: //! Spawn a process and open pipe with the specified type (READ or WRITE) - static bool executeBackground(const std::string& app, char* const argv[], PipeType type, ChildHandle& child); + static bool executeBackground(const std::string& cmd, char* const argv[], PipeType type, ChildHandle& child); //! Utility method. Cast argument to a C pointer required by some C-style functions. static inline char* castArgument(const std::string& arg); //! Utility method. Convert argument vector to a format required by execve and posix_spawn. - static std::vector<char*> castArgVector(const std::string& app, const std::vector<std::string>& argv); + static std::vector<char*> castArgVector(const std::string& cmd, const std::vector<std::string>& argv); //! Lightweight C++ wrapper with auto-close for file descriptors class FdWrapper { |