File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,13 @@ class PendingProcess
54
54
*/
55
55
public $ environment = [];
56
56
57
+ /**
58
+ * The standard input data that should be piped into the command.
59
+ *
60
+ * @var string|int|float|bool|resource|\Traversable|null
61
+ */
62
+ public $ input ;
63
+
57
64
/**
58
65
* Indicates whether output should be disabled for the process.
59
66
*
@@ -170,6 +177,19 @@ public function env(array $environment)
170
177
return $ this ;
171
178
}
172
179
180
+ /**
181
+ * Set the standard input that should be provided when invoking the process.
182
+ *
183
+ * @param \Traversable|resource|string|int|float|bool|null $input
184
+ * @return $this
185
+ */
186
+ public function input ($ input )
187
+ {
188
+ $ this ->input = $ input ;
189
+
190
+ return $ this ;
191
+ }
192
+
173
193
/**
174
194
* Disable output for the process.
175
195
*
@@ -281,6 +301,10 @@ protected function toSymfonyProcess(array|string|null $command)
281
301
$ process ->setIdleTimeout ($ this ->idleTimeout );
282
302
}
283
303
304
+ if ($ this ->input ) {
305
+ $ process ->setInput ($ this ->input );
306
+ }
307
+
284
308
if ($ this ->quietly ) {
285
309
$ process ->disableOutput ();
286
310
}
Original file line number Diff line number Diff line change 15
15
* @method static \Illuminate\Process\PendingProcess quietly()
16
16
* @method static \Illuminate\Process\PendingProcess tty(bool $tty = true)
17
17
* @method static \Illuminate\Process\PendingProcess options(array $options)
18
+ * @method static \Illuminate\Process\PendingProcess input(\Traversable|resource|string|int|float|bool|null $input)
18
19
* @method static \Illuminate\Contracts\Process\ProcessResult run(array|string|null $command = null, callable|null $output = null)
19
20
* @method static \Illuminate\Process\InvokedProcess start(array|string|null $command = null, callable $output = null)
20
21
* @method static \Illuminate\Process\PendingProcess withFakeHandlers(array $fakeHandlers)
Original file line number Diff line number Diff line change @@ -470,6 +470,18 @@ public function testRealProcessesDoesntThrowIfFalse()
470
470
$ this ->assertTrue (true );
471
471
}
472
472
473
+ public function testRealProcessesCanUseStandardInput ()
474
+ {
475
+ if (windows_os ()) {
476
+ $ this ->markTestSkipped ('Requires Linux. ' );
477
+ }
478
+
479
+ $ factory = new Factory ();
480
+ $ result = $ factory ->input ('foobar ' )->run ('cat ' );
481
+
482
+ $ this ->assertSame ('foobar ' , $ result ->output ());
483
+ }
484
+
473
485
public function testFakeInvokedProcessOutputWithLatestOutput ()
474
486
{
475
487
$ factory = new Factory ;
You can’t perform that action at this time.
0 commit comments