7
7
* This class represents a shell command.
8
8
*
9
9
* @author Michael Härtl <[email protected] >
10
- * @version 1.1.1 -dev
10
+ * @version 1.2.0 -dev
11
11
* @license http://www.opensource.org/licenses/MIT
12
12
*/
13
13
class Command
@@ -232,27 +232,30 @@ public function addArg($key, $value = null, $escape = null)
232
232
}
233
233
234
234
/**
235
+ * @param bool $trim whether to `trim()` the return value. The default is `true`.
235
236
* @return string the command output (stdout). Empty if none.
236
237
*/
237
- public function getOutput ()
238
+ public function getOutput ($ trim = true )
238
239
{
239
- return $ this ->_stdOut ;
240
+ return $ trim ? trim ( $ this -> _stdOut ) : $ this ->_stdOut ;
240
241
}
241
242
242
243
/**
244
+ * @param bool $trim whether to `trim()` the return value. The default is `true`.
243
245
* @return string the error message, either stderr or internal message. Empty if none.
244
246
*/
245
- public function getError ()
247
+ public function getError ($ trim = true )
246
248
{
247
- return $ this ->_error ;
249
+ return $ trim ? trim ( $ this -> _error ) : $ this ->_error ;
248
250
}
249
251
250
252
/**
253
+ * @param bool $trim whether to `trim()` the return value. The default is `true`.
251
254
* @return string the stderr output. Empty if none.
252
255
*/
253
- public function getStdErr ()
256
+ public function getStdErr ($ trim = true )
254
257
{
255
- return $ this ->_stdErr ;
258
+ return $ trim ? trim ( $ this -> _stdErr ) : $ this ->_stdErr ;
256
259
}
257
260
258
261
/**
@@ -288,7 +291,7 @@ public function execute()
288
291
if ($ this ->useExec ) {
289
292
$ execCommand = $ this ->captureStdErr ? "$ command 2>&1 " : $ command ;
290
293
exec ($ execCommand , $ output , $ this ->_exitCode );
291
- $ this ->_stdOut = trim ( implode ("\n" , $ output) );
294
+ $ this ->_stdOut = implode ("\n" , $ output );
292
295
if ($ this ->_exitCode !==0 ) {
293
296
$ this ->_stdErr = $ this ->_stdOut ;
294
297
$ this ->_error = empty ($ this ->_stdErr ) ? 'Command failed ' : $ this ->_stdErr ;
@@ -303,8 +306,8 @@ public function execute()
303
306
304
307
if (is_resource ($ process )) {
305
308
306
- $ this ->_stdOut = trim ( stream_get_contents ($ pipes [1 ]) );
307
- $ this ->_stdErr = trim ( stream_get_contents ($ pipes [2 ]) );
309
+ $ this ->_stdOut = stream_get_contents ($ pipes [1 ]);
310
+ $ this ->_stdErr = stream_get_contents ($ pipes [2 ]);
308
311
fclose ($ pipes [1 ]);
309
312
fclose ($ pipes [2 ]);
310
313
0 commit comments