Hello,
How to execute Sage commands from C++? I could only find answers to do the
other way around.
Please excuse me if this question was answered before, but after some
search I couldn't find the answer. I've found the related discussion here :
http://ask.sagemath.org/question/9133/using-features-of-sage-in-c/ , but
does it mean that the answer to my question is: "you cannot do that"?
I would like to use it as for example Matlab allows:
Engine *ep;
if (!(ep = engOpen(NULL))) {
exit(-1);
}
mxArray *res1 = NULL;
engEvalString(ep,"res = 2+2");
res1 = engGetVariable(ep,"res");
string result = mxArrayToString(res1);
engClose(ep);
So far I found only the very rough workaround:
FILE* sage_output;
string solveString = "2+2";
std::stringstream ss;
ss << "echo \"" << solveString << "\" | sage";
sage_output = popen(ss.str(), "r");
int line_count = 0;
while (fgets(str_buf, MAX_LEN + 1, sage_output) != NULL) {
line_count++;
if (line_count == 6) {
result = str_buf;
result = result.substr(6, strlen(str_buf) - 7);
}
}
pclose(sage_output);
Which works for a simple input, but it starts a new Sage process each time
(so I cannot store variables). And it requires parsing the large output to
find the result.
Thank you
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.