Skip to content

Instantly share code, notes, and snippets.

@cameronjacobson
Created March 19, 2014 02:30
Show Gist options
  • Save cameronjacobson/9634461 to your computer and use it in GitHub Desktop.
Save cameronjacobson/9634461 to your computer and use it in GitHub Desktop.
Programmatic access to GNU Octave
<?php
$octave_command = "octave --no-window-system -q";
$spec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/octave_stderr.txt", "a")
);
$proc = proc_open($octave_command, $spec, $pipes, '/tmp');
if (is_resource($proc)) {
while($command = fgets(STDIN)) {
echo 'REQUEST : '.$command;
fwrite($pipes[0], $command);
$line = fgets($pipes[1]);
list(,$ans) = explode('ans =',$line,2);
if(in_array(trim($command),array('quit','exit'))) {
break;
}
echo 'RESPONSE: '.ltrim($ans);
}
fclose($pipes[0]);
fclose($pipes[1]);
$return = proc_close($proc);
echo 'EXITING: '.$return.PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment