It may be better to try to use the sage api that Robert Bradshaw wrote
but which not many people have explored.  Some explanation of it is in
the trac patch:

http://trac.sagemath.org/sage_trac/ticket/2346

and some discussion at:

http://groups.google.com/group/sage-edu/browse_thread/thread/f2935bb4ddb72dc5/04f9d2d104577fba?lnk=gst&q=api#04f9d2d104577fba

Cheers,
Marshall Hampton

On Jan 13, 9:32 am, Jason Grout <jason-s...@creativetrax.com> wrote:
> ben wrote:
> > Hello,
>
> > I'm trying to communicate with sage using PHP. I want it to calculate
> > 1+2. I've written this little bash script:
>
> > #!/bin/bash
> > cd /usr/local/sage-3.2.1
> > ./sage  -q << END
> > 1+2
> > END
> > read -p "Press enter to continue"
>
> > which outputs:
>
> > sage: 3
> > sage:
> > Exiting SAGE (CPU time 0m0.04s, Wall time 0m0.04s).
> > Press enter to continue
>
> > however, when I execute the script from PHP using this:
>
> > echo exec("cd /home/ben/Desktop && ./test.sh",$out);
> > print_r($out);
>
> > it outputs:
>
> > **********************************************************************
> > Welcome to IPython. I will try to create a personal configuration
> > directory  where you can customize many aspects of IPython's
> > functionality in: /root/.sage/ipython  Initializing from
> > configuration /usr/local/sage-3.2.1/local/lib/python2.5/site-packages/
> > IPython/UserConfig Please press  to start
> > IPython.**********************************************************************
> > Press enter to exit:
>
> > why do I not get the same output as when I execute the script
> > directly? is there any way stopping the welcome message being output
> > every time? how can I get the answer 3?
>
> It looks like sage is being run as a different user when you are using
> php (as root user!).  First, I would be extremely careful when running
> Sage this way; there are lots of obvious and subtle security implications.
>
> That said, you can probably get the configuration messages over with by
> just running Sage once as the user in question (again, it looks like root).
>
> I would highly recommend not running Sage as root (as appears to be done
> above) unless you know exactly what you are doing.
>
> Jason
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to