So I'm looking at the php.net manual page for proc_open and have tried to fit my scenario into it. Here's what I have:
<?php
// Set the variable for the pw
$var= "test";
$descriptorspec = array(
0 => array("pipe","r"),
1 => array("pipe","w"),
2 => array("file","./error.log","a")
);
// define current working directory where files would be stored
$cwd = "./";
// open process
$process = proc_open("/path/to/program", $descriptorspec, $pipes, $cwd);
if(is_resource($process)){
// anatomy of $pipes: 0 => stdin, 1 => stdout, 2 => error log
fwrite($pipes[0], "echo $var");
fwrite($pipes[0], "echo $var");
fclose($pipes[0]);
// print pipe output
echo stream_get_contents($pipes[1]);
// close pipe
fclose($pipes[1]);
// all pipes must be closed before calling proc_close.
// proc_close() to avoid deadlock
proc_close($process);
}
?>
The prompt that the program generates is to set a password. So the prompt from a terminal is "Enter Password". Instead of writing to the pipes, the php script hangs and must be terminated. The error.log file is created and the prompt "Enter Password" is output to it.