ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 26 Nov 2019 16:26:54 +0100Grabbing Output in Linuxhttps://ask.sagemath.org/question/48884/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.Tue, 26 Nov 2019 01:03:50 +0100https://ask.sagemath.org/question/48884/grabbing-output-in-linux/Comment by Emmanuel Charpentier for <p>Hello!</p>
<p>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 <em>sage -c that-string</em>. 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. </p>
<p>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.</p>
https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48886#post-id-48886I do not understand where is the problem. What forbids you to do:
sage: os.system("cat that-string.txt | yourPascalProgram")
For all practical purposes, Sage *is* a Python interpreter...Tue, 26 Nov 2019 06:29:07 +0100https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48886#post-id-48886Comment by Kraig for <p>Hello!</p>
<p>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 <em>sage -c that-string</em>. 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. </p>
<p>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.</p>
https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48890#post-id-48890Sage 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.Tue, 26 Nov 2019 14:24:27 +0100https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48890#post-id-48890Comment by Iguananaut for <p>Hello!</p>
<p>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 <em>sage -c that-string</em>. 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. </p>
<p>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.</p>
https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48892#post-id-48892> 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.
Why not? That would probably be much cleaner.Tue, 26 Nov 2019 15:48:23 +0100https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48892#post-id-48892Comment by Iguananaut for <p>Hello!</p>
<p>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 <em>sage -c that-string</em>. 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. </p>
<p>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.</p>
https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48893#post-id-48893Ultimately, 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](https://pexpect.readthedocs.io/en/stable/) for this; it's the Python implementation of the [Expect](https://en.wikipedia.org/wiki/Expect) library. Maybe there is one for Pascal.Tue, 26 Nov 2019 15:55:32 +0100https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48893#post-id-48893Comment by Iguananaut for <p>Hello!</p>
<p>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 <em>sage -c that-string</em>. 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. </p>
<p>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.</p>
https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48894#post-id-48894You might even consider making your own [Sage interface](https://doc.sagemath.org/html/en/developer/coding_in_other.html#creating-a-new-pseudo-tty-interface) to your program (that documentation might be slightly out of date but it should point in the right direction).Tue, 26 Nov 2019 15:59:35 +0100https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48894#post-id-48894Comment by Kraig for <p>Hello!</p>
<p>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 <em>sage -c that-string</em>. 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. </p>
<p>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.</p>
https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48895#post-id-48895I actually asked this same question in my Pascal forum and they said "this sounds like a question to ask the sage community" and the sage community says to ask the Pascal community hahaha! I figured I'm an expert in neither language so I made an attempt to get more "expert" advice before trying to do this on my own. I have an idea to just attach a file to sage and run the sage process with that attached file forever in Pascal, and then update the attached file whenever code is needed (which runs it in sage) and then write the output to another file which I then grab from.Tue, 26 Nov 2019 16:26:54 +0100https://ask.sagemath.org/question/48884/grabbing-output-in-linux/?comment=48895#post-id-48895