<?php
require_once($_SERVER['PM_BASE_CONFIG_PATH']);
class maxima_core {
private $executable_command;
protected $dbg_bool;
protected $dbg_info;
public function __construct($dbg=FALSE){
$this->executable_command=constant('PM_MAXIMA_EXEC_CMD');
$this->dbg_bool=$dbg;
$this->dbg_info="";
}
protected function exec($query){// to include package that is loaded by init_command
$descriptor = 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/error-log.txt", "a")//constant('PM_SERVER_LOG_DIR')."/maxima/error.log", "a") // stderr is a file to write to
);
$cwd=constant('PM_ACTIVITY_PLUGIN_URL')."/engine_solver";
$MAXIMA_DIR = constant('PM_ACTIVITY_PLUGIN_DIR');
$env=array();
$init_command="display2d:false$" . "PM_ACTIVITY_PLUGIN_URL: \"" . $MAXIMA_DIR . "\"$";
//'load("/home/gabriel/github/moodledata/stack/maximalocal.mac");';
$exec_cmd=$this->executable_command." --quiet";
// --userdir='".constant('PM_ACTIVITY_PLUGIN_DIR')."/engine_solver/maxima_userdir'";
// change
$result=NULL;
$process=proc_open($exec_cmd,$descriptor,$pipes,$cwd,$env);
if(is_resource($process)){
if (!fwrite($pipes[0], $init_command)) {
echo "<br />Could not write to the CAS process!<br />\n";
} else {
fwrite($pipes[0], $query);
fwrite($pipes[0], "quit();");
fclose($pipes[0]);
$result=stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
}
}
return $result;
}
public function dbg_info(){
return $this->dbg_info;
}
}
?>
我不熟悉maxima語法,所以代碼只是我想要實現的一個例子......如果我將maxima作爲php擴展添加,如何從maxima腳本中檢索輸出? – Boyang
嘗試將最大化腳本中的變量'de'作爲變量,然後回顯變量以查看它出來的天氣。或者只是在循環後添加maxima腳本中的代碼 –
它是如此工作? –