Skip to content

Commit e8cbcde

Browse files
committed
Update readme and changelog
1 parent 8d139be commit e8cbcde

File tree

2 files changed

+117
-11
lines changed

2 files changed

+117
-11
lines changed

CHANGELOG.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11
# CHANGELOG
22

3+
## 1.6.4
4+
5+
* Let getExecCommand() not cache the created command string
6+
7+
## 1.6.3
8+
9+
* Include PHP 5.3 in version requirements
10+
11+
## 1.6.2
12+
13+
* Add .gitattributes to reduce package size
14+
15+
## 1.6.1
16+
17+
* Issue #44 Fix potential security issue with escaping shell args (@Kirill89 / https://snyk.io/)
18+
19+
## 1.6.0
20+
21+
* Issue #24 Implement timeout feature
22+
23+
## 1.5.0
24+
25+
* Issue #20 Refactor handling of stdin/stdou/sterr streams with proc_open().
26+
By default these streams now operate in non-blocking mode which should fix
27+
many hanging issues that were caused when the command received/sent a lot of
28+
input/output. This is the new default on Non-Windows systems (it's not
29+
supported on Windows, though). To get the old behavior the nonBlockingMode
30+
option can be set to false.
31+
32+
## 1.4.1
33+
34+
* Allow command names with spaces on Windows (@Robindfuller )
35+
36+
## 1.4.0
37+
38+
* Allow stdin to be a stream or a file handle (@Arzaroth)
39+
40+
## 1.3.0
41+
42+
* Add setStdIn() which allows to pipe an input string to the command (@martinqvistgard)
43+
44+
## 1.2.5
45+
46+
* Issue #22 Fix execution of relative file paths on windows
47+
48+
## 1.2.4
49+
50+
* Reverted changes for Issue #20 as this introduced BC breaking problems
51+
52+
## 1.2.3
53+
54+
* Issue #20: Read stderr before stdout to avoid hanging processes
55+
356
## 1.2.2
457

558
* Issue #16: Command on different drive didn't work on windows

README.md

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ composer require mikehaertl/php-shellcommand
2828
* Catches `stdOut`, `stdErr` and `exitCode`
2929
* Handle argument escaping
3030
* Pass environment vars and other options to `proc_open()`
31+
* Pipe resources like files or streams into the command
32+
* Timeout for execution
3133

3234
## Examples
3335

@@ -49,7 +51,69 @@ if ($command->execute()) {
4951

5052
### Advanced Features
5153

54+
#### Add Arguments
5255
```php
56+
<?php
57+
$command = new Command('/bin/somecommand');
58+
// Add arguments with correct escaping:
59+
// results in --name='d'\''Artagnan'
60+
$command->addArg('--name=', "d'Artagnan");
61+
62+
// Add argument with several values
63+
// results in --keys key1 key2
64+
$command->addArg('--keys', array('key1','key2'));
65+
```
66+
67+
### Pipe Input Into Command
68+
69+
From string:
70+
```php
71+
<?php
72+
$command = new ('jq') // jq is a pretty printer
73+
$command->setStdIn('{"foo": 0}');
74+
if (!$command->execute()) {
75+
echo $command->getError();
76+
} else {
77+
echo $command->getOutput();
78+
}
79+
// Output:
80+
// {
81+
// "foo": 0
82+
// }
83+
```
84+
85+
From file:
86+
```php
87+
<?php
88+
$fh = fopen('test.json', 'r');
89+
// error checks left out...
90+
$command = new Command('jq');
91+
$command->setStdIn($fh);
92+
if (!$command->execute()) {
93+
echo $command->getError();
94+
} else {
95+
echo $command->getOutput();
96+
}
97+
fclose($fh);
98+
```
99+
From URL:
100+
```php
101+
<?php
102+
$fh = fopen('https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m,relativehumidity_2m,windspeed_10m', 'r');
103+
// error checks left out...
104+
$command = new Command('jq');
105+
$command->setStdIn($fh);
106+
if (!$command->execute()) {
107+
echo $command->getError();
108+
} else {
109+
echo $command->getOutput();
110+
}
111+
fclose($fh);
112+
```
113+
114+
#### Set Command Instance Options
115+
```php
116+
<?php
53117
// Create command with options array
54118
$command = new Command(array(
55119
'command' => '/usr/local/bin/mycommand',
@@ -64,17 +128,6 @@ $command = new Command(array(
64128
'bypass_shell' => true,
65129
),
66130
));
67-
68-
// Add arguments with correct escaping:
69-
// results in --name='d'\''Artagnan'
70-
$command->addArg('--name=', "d'Artagnan");
71-
72-
// Add argument with several values
73-
// results in --keys key1 key2
74-
$command->addArg('--keys', array('key1','key2'));
75-
76-
// Add string to pipe to command on standard input
77-
$command->setStdIn('string');
78131
```
79132

80133
## API

0 commit comments

Comments
 (0)