Grabbing Output in Linux
Hello!
I have a great deal of code written in Pascal, and this code runs on a linux terminal. Currently, the only way I can run sage math through this program is to do the following: type a list of commands to run in sage as a concatenated strings separated by semicolons, and I then write the output to a textfile. For example 'load(''whatever'');function_call(something);... > sometextfile.txt'. This entire line is written in a call to the terminal. Effectively what is fed is sage -c that-string. The problem with this method is it adds time because sage has to open and close every time it runs. Is there a command in sage that allows me to keep the sage terminal persistent and I then ping that terminal with new commands. I assume the way to ping with new commands is to pipe from one terminal to the one running sage, but I am not a unix connisseur.
Of course, the easiest method is to run my code via python and have python run the pascal code. This is, unfortunately, not an option.
I do not understand where is the problem. What forbids you to do:
For all practical purposes, Sage is a Python interpreter...
Sage is also a computer algebra system. I have an entire program written in another language, so I was wondering if there was some fast way to have my program run sage to get output.
Why not? That would probably be much cleaner.
Ultimately, if you really wanted to keep open a Sage interpreter and essentially "screen scrape" it you could do that; most of Sage's original (and some still) interfaces to other CASes are doing exactly that, though there has been a move toward tighter low-level library interfacing since this way of doing this is woefully inefficient. But then your question becomes a Pascal programming question, of how to run a subprocess and interact with its standard I/O streams. There is nothing to be done from the Sage end (e.g. as you wrote "a command in sage") that would facilitate this. In Python we use pexpect for this; it's the Python implementation of the Expect library. Maybe there is one for Pascal.
You might even consider making your own Sage interface to your program (that documentation might be slightly out of date but it should point in the right direction).