15
15
16
16
namespace myvas {
17
17
18
+ /* *
19
+ * @brief Default timeout 10 seconds.
20
+ */
18
21
const int64_t CMDOUT_TIMEOUT_MILLISECONDS = 10 * 1000 ;
19
22
20
23
/* *
@@ -32,7 +35,7 @@ class cmdout
32
35
/* *
33
36
* @brief Gets the exit code after exec returned.
34
37
*
35
- * The value is one of the following:
38
+ * @return The value is one of the following:
36
39
* - If cmd is empty, then a nonzero value if a shell is available, or 0 if
37
40
* no shell is available.
38
41
* - If a child process in cmd could not be created, or its status could not
@@ -43,23 +46,45 @@ class cmdout
43
46
* last command in cmd.
44
47
*/
45
48
int status () const ;
49
+
50
+ /* *
51
+ * @brief Sets the status value.
52
+ */
46
53
cmdout& status (int );
47
54
48
55
/* *
49
56
* @brief Gets the content of stdout (file descriptor 1).
50
57
*/
51
58
std::string out () const ;
59
+ /* *
60
+ * @brief Sets the out string.
61
+ */
52
62
cmdout& out (const std::string&);
53
63
54
64
/* *
55
65
* @brief Gets the shell command line.
56
66
*/
57
67
std::string cmd () const ;
68
+ /* *
69
+ * @brief Sets the cmd string.
70
+ */
58
71
cmdout& cmd (const std::string&);
59
72
73
+ /* *
74
+ * @brief Gets the timeout duration in milliseconds.
75
+ */
60
76
std::chrono::milliseconds timeout () const ;
77
+ /* *
78
+ * @brief Gets the timeout in milliseconds.
79
+ */
61
80
int64_t timeout_ms () const ;
81
+ /* *
82
+ * @brief Sets the timeout.
83
+ */
62
84
cmdout& timeout (std::chrono::milliseconds);
85
+ /* *
86
+ * @brief Sets the timeout value.
87
+ */
63
88
cmdout& timeout (int64_t );
64
89
65
90
/* *
@@ -73,9 +98,6 @@ class cmdout
73
98
*
74
99
* @param cmd The cmd argument is a pointer to a null-terminated string
75
100
* containing a shell command.
76
- *
77
- * @return The return value is a cmdout object, in which wraps the status code
78
- * and output string of the shell command.
79
101
*/
80
102
explicit cmdout (const std::string& cmd);
81
103
@@ -88,9 +110,6 @@ class cmdout
88
110
* containing a shell command.
89
111
*
90
112
* @param timeout_ms timeout in milliseconds. (If zero, defaults to 10 seconds)
91
- *
92
- * @return The return value is a cmdout object, in which wraps the status code
93
- * and output string of the shell command.
94
113
*/
95
114
explicit cmdout (const std::string& cmd, int64_t timeout_ms);
96
115
@@ -102,44 +121,76 @@ class cmdout
102
121
* containing a shell command.
103
122
*
104
123
* @param timeout timeout duration. (If zero, defaults to 10 seconds)
105
- *
106
- * @return The return value is a cmdout object, in which wraps the status code
107
- * and output string of the shell command.
108
124
*/
109
125
explicit cmdout (const std::string& cmd, std::chrono::milliseconds timeout);
110
126
111
127
/* *
112
128
* @brief Constructs an output.
113
129
*
130
+ * @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
131
+ * @param timeout timeout duration. (If zero, defaults to 10 seconds)
114
132
* @param status EXIT_SUCCESS, EXIT_FAILURE or errno
133
+ * @param out output string
134
+ *
115
135
* @see cerrno and cstdlib.
116
136
*/
117
137
explicit cmdout (const std::string& cmd, std::chrono::milliseconds timeout, int status, const std::string& out);
138
+ /* *
139
+ * @brief Constructs an output.
140
+ *
141
+ * @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
142
+ * @param timeout_ms timeout. (If zero, defaults to 10 seconds)
143
+ * @param status EXIT_SUCCESS, EXIT_FAILURE or errno
144
+ * @param out output string
145
+ *
146
+ * @see cerrno and cstdlib.
147
+ */
118
148
explicit cmdout (const std::string& cmd, int64_t timeout_ms, int status, const std::string& out);
119
149
150
+ /* *
151
+ * @brief Copy constructor.
152
+ */
120
153
cmdout (const cmdout&);
154
+ /* *
155
+ * @brief Copy assignment.
156
+ */
121
157
cmdout& operator =(const cmdout&);
158
+ /* *
159
+ * @brief Move constructor.
160
+ */
122
161
cmdout (cmdout&&);
162
+ /* *
163
+ * @brief Move assignment.
164
+ */
123
165
cmdout& operator =(cmdout&&);
124
166
167
+ /* *
168
+ * @brief Destructor.
169
+ */
125
170
virtual ~cmdout ();
126
171
127
172
/* *
128
173
* @brief Execute a specified shell command with arguments initialized in this class.
174
+ *
175
+ * @return The return value is a cmdout reference, in which wraps the status code
176
+ * and output string of the shell command.
129
177
*/
130
178
cmdout& exec ();
131
179
};
132
180
133
181
/* *
134
182
* @brief Execute a shell command specified in cmd.
135
183
*
184
+ * @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
185
+ *
136
186
* @return Returns a cmdout object (without timeout)
137
187
*/
138
188
cmdout system (const std::string& cmd);
139
189
140
190
/* *
141
191
* @brief Execute a shell command specified in cmd and get its output before time runs out.
142
192
*
193
+ * @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
143
194
* @param timeout timeout duration, defaults to 10 seconds
144
195
*
145
196
* @return Returns a cmdout object
@@ -149,6 +200,7 @@ cmdout system_timeout(const std::string& cmd, std::chrono::milliseconds timeout)
149
200
/* *
150
201
* @brief Execute a shell command specified in cmd and get its output before time runs out.
151
202
*
203
+ * @param cmd The cmd argument is a pointer to a null-terminated string containing a shell command.
152
204
* @param timeout_ms timeout in milliseconds, defaults to 10 seconds
153
205
*
154
206
* @return Returns a cmdout object
0 commit comments