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];