使用system,exec或passthru从PHP调用Octave

I am trying to execute an Octave script from PHP in the eclipse environment. The set up PHP, Apache works yet. The problem occurs related to the following call:

$cmd = "octave3.8 -qf /.../path_to_file/myscript.m file.txt";
$ex = passthru($cmd, $output);
var_dump($ex);
var_dump($output); 

inside the script myscript.m there is:

e = 5                % too see if it will be printed onto the web page
arg = argv();        
data = load(arg{1}); 

The result is : NULL int(1)

Few keynotes:

  • The same command from the terminal works fine (octave3.8 -qf /../path_to_file/myscript.m file.txt)
  • I already tried to put the PHP process to be run by a sudoer

On Ubuntu 12.04, Octave 3.8.0, Eclipse standard/SDK 2.0.1., PHP Dev Tools 3.2.0.

Your command line should be:

octave --no-gui --quiet /path/to/script.m

and the contents of the script should be:

e = 5;
disp(e);

Really you want to do this? New Octave version of does not support pipes. You may face many security problem when user type commands like file or system related octave functions. New graphics toolkit fltk will hang when you are using octave through pipe. Still you are interested search online octave on google. Hm. There is Nclab, its a cloud based.