Commit | Line | Data |
---|---|---|
8de51304 H |
1 | #!/usr/bin/php |
2 | <?php | |
3 | if($argc < 2) die("usage: pwrap command\n"); | |
4 | for($i=1;$i<$argc;$i++) $command = $command.' '.$argv[$i]; | |
5 | ||
6 | $descriptorspec = array( | |
7 | 0 => array("pipe", "r"), // stdout | |
8 | 1 => array("pipe", "w"), // stdin | |
9 | //2 => array("pipe", "r") // stderr | |
10 | //2 => array("file", "./error-output.txt", "a") // stderr is a file to write to | |
11 | ); | |
12 | ||
13 | $cwd = '~/'; | |
14 | ||
15 | $process = proc_open($command, $descriptorspec, $pipes, $cwd, $_ENV); | |
16 | $stdin = fopen('php://stdin', 'r'); | |
17 | ||
18 | stream_set_blocking($pipes[0], 0); | |
19 | stream_set_blocking($pipes[1], 0); | |
20 | //stream_set_blocking($pipes[2], 0); | |
21 | stream_set_blocking($stdin, 0); | |
22 | ||
23 | while(!feof($pipes[0]) && !feof($pipes[1])) { | |
24 | echo(fgetc($pipes[1])); | |
25 | fwrite($pipes[0], fgetc($stdin)); | |
26 | } |