简体   繁体   中英

Execute multiple sage commands from php script

I have installed Sage math on my ubuntu server. I can run sage commands by ssh terminal such as

$sage:   
$sage:  f = x^2
$sage:  f.diff(x)

I would like to do on a php script

exec('sage');
exec('sage: f = 5x^3');
$fprime = exec('sage: latex(f.diff(x))');

echo $fprime; 

I would expect "15x^2" as output but that's not happening .. however on ssh terminal all is good..
all help would be greatly appreciated..

I'm not completely sure of what you want to achieve. PHP's exec function executes a shell command, and that's all. Read http://fr2.php.net/manual/en/function.exec.php .

sage: f = 5*x^3 is not a shell command. You can run sage scripts directly via the command line using the -c switch :

./sage -c 'print latex((5*x^3).diff())'

will print 15 \\, x^{2} to the terminal. In PHP you can grab this output by passing a second argument to exec :

exec("./sage -c 'print latex((5*x^3).diff())'", $output);
echo $output[0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM