77 * This class represents a shell command.
88 *
99 * @author Michael Härtl <[email protected] > 10- * @version 1.1.1 -dev
10+ * @version 1.2.0 -dev
1111 * @license http://www.opensource.org/licenses/MIT
1212 */
1313class Command
@@ -232,27 +232,30 @@ public function addArg($key, $value = null, $escape = null)
232232 }
233233
234234 /**
235+ * @param bool $trim whether to `trim()` the return value. The default is `true`.
235236 * @return string the command output (stdout). Empty if none.
236237 */
237- public function getOutput ()
238+ public function getOutput ($ trim = true )
238239 {
239- return $ this ->_stdOut ;
240+ return $ trim ? trim ( $ this -> _stdOut ) : $ this ->_stdOut ;
240241 }
241242
242243 /**
244+ * @param bool $trim whether to `trim()` the return value. The default is `true`.
243245 * @return string the error message, either stderr or internal message. Empty if none.
244246 */
245- public function getError ()
247+ public function getError ($ trim = true )
246248 {
247- return $ this ->_error ;
249+ return $ trim ? trim ( $ this -> _error ) : $ this ->_error ;
248250 }
249251
250252 /**
253+ * @param bool $trim whether to `trim()` the return value. The default is `true`.
251254 * @return string the stderr output. Empty if none.
252255 */
253- public function getStdErr ()
256+ public function getStdErr ($ trim = true )
254257 {
255- return $ this ->_stdErr ;
258+ return $ trim ? trim ( $ this -> _stdErr ) : $ this ->_stdErr ;
256259 }
257260
258261 /**
@@ -288,7 +291,7 @@ public function execute()
288291 if ($ this ->useExec ) {
289292 $ execCommand = $ this ->captureStdErr ? "$ command 2>&1 " : $ command ;
290293 exec ($ execCommand , $ output , $ this ->_exitCode );
291- $ this ->_stdOut = trim ( implode ("\n" , $ output) );
294+ $ this ->_stdOut = implode ("\n" , $ output );
292295 if ($ this ->_exitCode !==0 ) {
293296 $ this ->_stdErr = $ this ->_stdOut ;
294297 $ this ->_error = empty ($ this ->_stdErr ) ? 'Command failed ' : $ this ->_stdErr ;
@@ -303,8 +306,8 @@ public function execute()
303306
304307 if (is_resource ($ process )) {
305308
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 ]);
308311 fclose ($ pipes [1 ]);
309312 fclose ($ pipes [2 ]);
310313
0 commit comments