<?php if ($_POST['submit']=="Submit") { $arg1 = $_POST["LHS"]; $arg2 = $_POST["RHS"]; if (!empty($arg1) && !empty($arg2)) { $descriptorspec =array( 0=>array("pipe", "r"), // stdin is a pipe that the child will read from 1=>array("pipe", "w"), // stdout is a pipe that the child will write to 2=>array("file", "/tmp/adder-error.log", "a") // stderr is a file to write to ); // $result=$arg1+$arg2; // echo "the answer is ".$result; $process = proc_open("/var/www/cgi-bin/adder", $descriptorspec, $pipes); if (is_resource($process)) { // $pipes now looks like this: // 0=>writable handle connected to child stdin // 1=>readable handle connected to child stdout // Any error will be appended to /tmp.adder-error.log fwrite($pipes[0], "$arg1 $arg2\n"); fclose($pipes[0]); // $result = -1; // fscanf($pipes[1], " %d", $result); echo "the answer is ". stream_get_contents($pipes[1]); fclose($pipes[1]); $return_value = proc_close($process); } } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <form action="index.php" method="post"> First argument: <input type="text" name="LHS" maxlength="50"><br /> Second argument: <input type="text" name="RHS" maxlength="50"><br /> Press to compute: <input type="submit" name="submit" value="Submit"> </form> </body> </html> |