fix to allow proc_open() to accept php://stdin as stdin
[hiphop-php.git] / hphp / test / slow / ext_process / lwp.php
blob0a45f3736be865e9f232048eff7babec5de9c81e
1 <?php
3 function VS($x, $y) {
4 var_dump($x === $y);
5 if ($x !== $y) { echo "Failed: $y\n"; echo "Got: $x\n";
6 var_dump(debug_backtrace()); }
8 function VERIFY($x) { VS($x != false, true); }
10 //////////////////////////////////////////////////////////////////////
12 $output = shell_exec("echo hello");
13 VS($output, "hello\n");
15 chdir("/tmp/");
16 VS(shell_exec("/bin/pwd"), "/tmp\n");
18 pcntl_signal_dispatch();
20 $last_line = exec("echo hello; echo world;", $output, $ret);
21 VS($output, array("hello", "world"));
22 VS($last_line, "world");
23 VS($ret, 0);
25 chdir("/tmp/");
26 VS(exec("/bin/pwd"), "/tmp");
28 echo "heh\n";
30 passthru("echo hello; echo world;", $ret);
31 VS($ret, 0);
33 chdir("/tmp/");
34 passthru("/bin/pwd");
36 $last_line = system("echo hello; echo world;", $ret);
37 VS($last_line, "world");
38 VS($ret, 0);
40 chdir("/tmp/");
41 VS(system("/bin/pwd"), "/tmp");
43 $errout = tempnam('/tmp', 'vmtesterrout');
44 unlink($errout);
46 $descriptorspec =
47 array(array("pipe", "r"),
48 array("pipe", "w"),
49 array("file", $errout, "a"));
51 putenv("inherit_me=please");
52 $process = proc_open('echo $inherit_me', $descriptorspec, $pipes);
53 VERIFY($process != false);
55 fpassthru($pipes[1]);
57 VS(proc_close($process), 0);
59 // Ensure that PATH makes it through too
60 $process = proc_open('echo $PATH', $descriptorspec, $pipes);
61 VERIFY($process != false);
63 VERIFY(strlen(fgets($pipes[1])) > 2);
65 VS(proc_close($process), 0);
67 $descriptorspec =
68 array(array("pipe", "r"),
69 array("pipe", "w"),
70 array("file", $errout, "a"));
71 $cwd = "/tmp";
73 $process = proc_open("sh", $descriptorspec, $pipes, $cwd);
74 VERIFY($process != false);
76 fprintf($pipes[0], "echo Sup");
77 fclose($pipes[0]);
78 fpassthru($pipes[1]);
79 VS(proc_close($process), 0);
81 $descriptorspec =
82 array(array("pipe", "r"),
83 array("pipe", "w"),
84 array("file", $errout, "a"));
85 $process = proc_open('cat', $descriptorspec, $pipes);
86 VERIFY($process != false);
87 VERIFY(proc_terminate($process));
88 // still need to close it, not to leave a zombie behind
89 proc_close($process);
91 $process = proc_open('cat', $descriptorspec, $pipes);
92 VERIFY($process != false);
93 $ret = proc_get_status($process);
94 VS($ret['command'], 'cat');
95 VERIFY($ret['pid'] > 0);
96 VERIFY($ret['running']);
97 VERIFY(!$ret['signaled']);
98 VS($ret['exitcode'], -1);
99 VS($ret['termsig'], 0);
100 VS($ret['stopsig'], 0);
101 proc_close($process);
103 VERIFY(proc_nice(0));
105 VS(escapeshellarg("\""), "'\"'");
107 VS(escapeshellcmd("perl \""), "perl \\\"");