Hello,
I am having some very unexpected results while trying to create a custom CLI using PHP. Let’s forgo any “Why would you do that?” questions for the moment.
$cmd = 'FOO="bar"';
putenv($cmd);
//this is actually defined in a class
function _($cmd, $returnType = RET_OBJECT) {
$d['output'] = '';
$d['error'] = '';
$descriptorspec = array(0 => array('pipe','r'),
1 => array('pipe','w'),
2 => array('pipe','w'));
$process = proc_open($cmd,$descriptorspec,$pipes);
if (is_resource($process)) {
//fwrite($pipes[0]);
fclose($pipes[0]);
$d['output'] = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$d['error'] = stream_get_contents($pipes[2]);
fclose($pipes[2]);
proc_close($process);
} else {
Er::ror('Could not open process.',0); //custom error class
}
echo 'test output: '.$d['output']; //just for testing, but returns the same as the returned object
return Util::convertData($d,$returnType); //custom data converter
}
//the problem (don't use return object. instead, utilize the test echo statement):
_('echo "this is my foo${FOO}"');
// test output: this is my foo"bar"
I can’t figure out why the quotes are carrying over! I tried changed the double quotes to singles. I have tried double quoting. My last resort is to create a bash script on the fly and import it. I am confused. Any thoughts?