ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 08 Jan 2019 07:55:10 -0600Calling Sage from Javahttp://ask.sagemath.org/question/44853/calling-sage-from-java/Hello,
I am looking for a way to call Sage functions, such as constructing Polyhedra, from Java (on Windows).
In more detail, I want to do the following:
1. Input to Sage from Java: P1 = Polyhedron(vertices = [[0,2], [-1,0], [1,0], [0,0]])
2. Retrieve in Java the Sage output: P1.Hrepresentation()
It would be optimal if I could call Sage directly somehow, but if it's necessary, I think a python wrapper could also work. It would be very kind if somebody could point me in the right direction, maybe with code snippets, as I am very new to the Sage Environment.
Thank you.Wed, 02 Jan 2019 20:11:12 -0600http://ask.sagemath.org/question/44853/calling-sage-from-java/Answer by PatHooper for <p>Hello,</p>
<p>I am looking for a way to call Sage functions, such as constructing Polyhedra, from Java (on Windows).
In more detail, I want to do the following:</p>
<ol>
<li>Input to Sage from Java: P1 = Polyhedron(vertices = [[0,2], [-1,0], [1,0], [0,0]]) </li>
<li>Retrieve in Java the Sage output: P1.Hrepresentation()</li>
</ol>
<p>It would be optimal if I could call Sage directly somehow, but if it's necessary, I think a python wrapper could also work. It would be very kind if somebody could point me in the right direction, maybe with code snippets, as I am very new to the Sage Environment.</p>
<p>Thank you.</p>
http://ask.sagemath.org/question/44853/calling-sage-from-java/?answer=44957#post-id-44957Hello CupOfCoffee,
First some caveats: I don't use windows and I've never tried to connect sage to java.
I think you should be able to run programs in Java with ProcessBuilder (https://docs.oracle.com/javase/6/docs/api/java/lang/ProcessBuilder.html). I expect you'd need to pass some parameters to sage to get it working correctly. Here are some relevant links:
- https://stackoverflow.com/questions/5604698/java-programming-call-an-exe-from-java-and-passing-parameters - StackOverflow question on passing parameters to ProcessBuilder
- http://doc.sagemath.org/html/en/reference/repl/options.html - Command line options for sage
Then I would think you would want to pass and read commands to Sage through input/output to the process. There is a StackOverflow question addressing this here: https://stackoverflow.com/questions/18903549/writing-to-inputstream-of-a-java-process
I imagine if you want to just do what you are suggesting, this wouldn't be too bad, but if you want to do something more complex, dealing with the input/output could be a pain.
Best,
Pat
PS. Sorry for mangling the links. The post wouldn't go through without it.Tue, 08 Jan 2019 07:55:10 -0600http://ask.sagemath.org/question/44853/calling-sage-from-java/?answer=44957#post-id-44957