-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
37 lines (30 loc) · 1.04 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
header('content-type: text/plain');
require_once __DIR__ . '/src/Process.php';
use xthukuh\Process;
$proc = new Process($cmd = sprintf('%s --version', Process::is_win() ? 'php' : '/usr/local/bin/php'));
$output = null;
$success = $proc -> open($background=false, $callback=function(Process $self) use (&$output){
$self -> output($callback=function(string $buffer) use (&$output){
if (is_null($output)) $output = '';
$output .= $buffer;
});
});
if ($success){
print(sprintf("process successful: pid=%s, exit=%s, output=\n--------------------\n%s\n--------------------\n", $proc -> pid, $proc -> exit, $output));
exit(0);
}
else {
print(sprintf("process failure: error='%s'\n", $proc -> error));
exit(1);
}
/*
PS C:\www\process> php example.php
process successful: pid=10956, exit=0, output=
--------------------
PHP 7.3.31 (cli) (built: Sep 21 2021 12:17:30) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.31, Copyright (c) 1998-2018 Zend Technologies
--------------------
PS C:\www\process>
*/