Skip to content

Commit 56e1acf

Browse files
committedApr 19, 2023
Issue #61 Add form feed to trimmed characters
1 parent 6c716ad commit 56e1acf

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed
 

‎README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
php-shellcommand
2-
===========
2+
================
33

44
[![GitHub Tests](https://github.com/mikehaertl/php-shellcommand/workflows/Tests/badge.svg)](https://github.com/mikehaertl/php-shellcommand/actions)
55
[![Packagist Version](https://img.shields.io/packagist/v/mikehaertl/php-shellcommand?label=version)](https://packagist.org/packages/mikehaertl/php-shellcommand)
@@ -61,15 +61,15 @@ $command->addArg('--name=', "d'Artagnan");
6161

6262
// Add argument with several values
6363
// results in --keys key1 key2
64-
$command->addArg('--keys', array('key1','key2'));
64+
$command->addArg('--keys', ['key1','key2']);
6565
```
6666

6767
### Pipe Input Into Command
6868

6969
From string:
7070
```php
7171
<?php
72-
$command = new ('jq') // jq is a pretty printer
72+
$command = new ('jq'); // jq is a pretty printer
7373
$command->setStdIn('{"foo": 0}');
7474
if (!$command->execute()) {
7575
echo $command->getError();
@@ -115,19 +115,19 @@ fclose($fh);
115115
```php
116116
<?php
117117
// Create command with options array
118-
$command = new Command(array(
118+
$command = new Command([
119119
'command' => '/usr/local/bin/mycommand',
120120

121121
// Will be passed as environment variables to the command
122-
'procEnv' => array(
122+
'procEnv' => [
123123
'DEMOVAR' => 'demovalue'
124-
),
124+
],
125125

126126
// Will be passed as options to proc_open()
127-
'procOptions' => array(
127+
'procOptions' => [
128128
'bypass_shell' => true,
129-
),
130-
));
129+
],
130+
]);
131131
```
132132

133133
## API
@@ -185,7 +185,7 @@ pass `command`, `execCommand` and `args` as options. This will call the respecti
185185
and `=`, the (optional) `$value` will be separated by a space. The key will get
186186
escaped if `$escapeArgs` is `true`.
187187
* `$value`: The optional argument value which will get escaped if `$escapeArgs` is `true`.
188-
An array can be passed to add more than one value for a key, e.g. `addArg('--exclude', array('val1','val2'))`
188+
An array can be passed to add more than one value for a key, e.g. `addArg('--exclude', ['val1','val2'])`
189189
which will create the option "--exclude 'val1' 'val2'".
190190
* `$escape`: If set, this overrides the `$escapeArgs` setting and enforces escaping/no escaping
191191
* `setStdIn()`: String or resource to supply to command via standard input.

‎src/Command.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -328,30 +328,36 @@ public function addArg($key, $value = null, $escape = null)
328328

329329
/**
330330
* @param bool $trim whether to `trim()` the return value. The default is `true`.
331+
* @param string $characters the list of characters to trim. The default
332+
* is ` \t\n\r\0\v\f`.
331333
* @return string the command output (stdout). Empty if none.
332334
*/
333-
public function getOutput($trim = true)
335+
public function getOutput($trim = true, $characters = " \t\n\r\0\v\f")
334336
{
335-
return $trim ? trim($this->_stdOut) : $this->_stdOut;
337+
return $trim ? trim($this->_stdOut, $characters) : $this->_stdOut;
336338
}
337339

338340
/**
339341
* @param bool $trim whether to `trim()` the return value. The default is `true`.
342+
* @param string $characters the list of characters to trim. The default
343+
* is ` \t\n\r\0\v\f`.
340344
* @return string the error message, either stderr or an internal message.
341345
* Empty string if none.
342346
*/
343-
public function getError($trim = true)
347+
public function getError($trim = true, $characters = " \t\n\r\0\v\f")
344348
{
345-
return $trim ? trim($this->_error) : $this->_error;
349+
return $trim ? trim($this->_error, $characters) : $this->_error;
346350
}
347351

348352
/**
349353
* @param bool $trim whether to `trim()` the return value. The default is `true`.
354+
* @param string $characters the list of characters to trim. The default
355+
* is ` \t\n\r\0\v\f`.
350356
* @return string the stderr output. Empty if none.
351357
*/
352-
public function getStdErr($trim = true)
358+
public function getStdErr($trim = true, $characters = " \t\n\r\0\v\f")
353359
{
354-
return $trim ? trim($this->_stdErr) : $this->_stdErr;
360+
return $trim ? trim($this->_stdErr, $characters) : $this->_stdErr;
355361
}
356362

357363
/**

0 commit comments

Comments
 (0)