我尝试使用像shell_exec()或system()这样的函数来执行php中的php脚本。示例:
<?php
chdir("C:\Program Files (x86)\Maxima-sbcl-5.35.1.2\bin");
$cmd = "maxima";
$res = exec($cmd,$out,$status);
echo "out=";
print_r($out);
echo "res=".$res.PHP_EOL;
echo "status=".$status.PHP_EOL;`
?>输出:
out=Array
(
[0] => Maxima 5.35.1.2 http://maxima.sourceforge.net
[1] => using Lisp SBCL 1.2.7
[2] => Distributed under the GNU Public License. See the file COPYING.
[3] => Dedicated to the memory of William Schelter.
[4] => The function bug_report() provides bug reporting information.
[5] => (%i1)
)
res=(%i1)
status=0在Match "(%i1)_“中,我必须运行类似于"solve(x^2-1=0,x)”的脚本;
但它不像cmd脚本那样被识别。
发布于 2015-05-30 05:40:25
您当前正尝试在交互模式下运行Maxima,就像您从shell启动命令并交互地输入表达式并返回结果一样。
你需要的是非交互模式。根据Maxima的man page,通常有两种方式在非交互模式下工作:--batch和--batch-string (也是--batch-lisp,但这里不相关)。
第一种方法要求您将一个文件名与要处理的表达式一起传递。第二种方法允许从命令行定义字符串。
在您的示例中,您应该像下面这样调用Maxima:
$expr = escapeshellarg("solve(x^2-1=0, x)");
$cmd = "maxima --batch-string=$expr";
// … and so on如果您想要执行更复杂的计算,则应该将它们转储到一个临时文件中,并通过--batch参数将文件位置传递给Maxima。
发布于 2016-09-04 13:53:20
您可以将文件中的命令字符串传递给Maxima,这是由命令行Maxima支持的。
如果您的操作系统是Linux/Unix/MacOS
在PHP中:
exec('maxima -q -b file');例如,此文件可以是input.txt,此文件中的内容为solve(x^2-1=0, x);stringout("result.txt", %o2);quit();
或
system('maxima -q -b file');如果您的操作系统是Win
$maximaDir = 'C:/Program Files (x86)/Maxima-sbcl-5.35.1.2'; // If your maxima is installed in elsewhere, please modified this location
exec($maximaDir.'/bin/maxima.bat -q -b "input.txt"');在Maxima中,您可以使用stringout();获取文件中的结果,然后在PHP中将文件作为字符串读取,您可以根据需要对字符串进行任何其他操作。
https://stackoverflow.com/questions/30534059
复制相似问题