Shell.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-01-11 17:02:51
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-08-22 14:09:54
  8. */
  9. /*
  10. *Environment:
  11. *Linux(Ubuntu), C++11,gcc 7.5.0,g++ 7.5.0
  12. *Description:
  13. *执行 Linux shell 命令并获取命令返回值或命令执行结果
  14. */
  15. #ifndef PARAMETER_FLOW
  16. #define PARAMETER_FLOW
  17. #define IN
  18. #define OUT
  19. #define INOUT
  20. #endif //PARAMETER_FLOW
  21. #ifndef BASE_TYPE_DEF
  22. #define BASE_TYPE_DEF
  23. #include <stdint.h>
  24. typedef int16_t SHORT;
  25. typedef uint16_t USHORT;
  26. typedef int32_t INT;
  27. typedef uint32_t UINT;
  28. typedef int64_t DLONG;
  29. typedef uint64_t DULONG;
  30. typedef void VOID;
  31. typedef bool BOOL;
  32. typedef char CHAR;
  33. typedef unsigned char UCHAR;
  34. typedef float FLOAT;
  35. typedef double DOUBLE;
  36. #endif //BASE_TYPE_DEF
  37. #include <string>
  38. #include <string.h>
  39. #include <utility>
  40. #include <vector>
  41. using std::make_pair;
  42. using std::pair;
  43. using std::string;
  44. using std::vector;
  45. class CShell
  46. {
  47. public:
  48. /*
  49. *Function : exeShellCmd
  50. *Description : 执行 Linux shell 命令并获取命令返回值
  51. *Modify : 2020.09.17
  52. *Input : IN const string& cmd = "",Linux shell 命令
  53. * : OUT INT* cmdReturnValue = nullptr,命令返回值
  54. *Return : pair<BOOL, string>,<函数是否执行成功,执行失败时的错误信息>
  55. *Caution :
  56. */
  57. static pair<BOOL, string> exeShellCmd(IN const string& cmd = "", OUT INT* cmdReturnValue = nullptr);
  58. /*
  59. *Function : exeShellCmd
  60. *Description : 执行 Linux shell 命令并获取命令执行结果
  61. *Modify : 2020.09.17
  62. *Input : IN const string& cmd,Linux shell 命令
  63. * : OUT vector<string>& results,命令执行结果
  64. *Return : pair<BOOL, string>,<函数是否执行成功,执行失败时的错误信息>
  65. *Caution :
  66. */
  67. static pair<BOOL, string> exeShellCmd(IN const string& cmd, OUT vector<string>& results);
  68. }; //Shell