Sagemath with java

89 views
Skip to first unread message

meryem afendi

unread,
Oct 11, 2021, 9:09:10 AM10/11/21
to sage-support
Hello everyone,
I tried to call SageMath from a java program using the Class ProcessBuilder. This code success to launch SageMath but when i want to use the InputStream to interact with Sage (For example a simple code 1+2) it does not work. iSageMath runs without sending the result of 1+2. 
Thank you.

 ProcessBuilder pb = new ProcessBuilder("C:\\Users\\Meryem\\AppData\\Local\\SageMath 9.2\\runtime\\bin\\mintty.exe", "-t","SageMath 9.2 Console", "-i", "sagemath.ico", "/bin/bash", "--login", "-c",  "/opt/sagemath-9.2/sage");
try 
         {
  
        Process p = pb.start();
        OutputStream stdin = p.getOutputStream();
                InputStream stdout = p.getInputStream();
              //InputStream stderr = p.getErrorStream();


                BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));

                writer.write("1+2" + "\n");
                writer.flush();
                writer.close();
                String line;
                while ((line = reader.readLine()) != null) {
                System.out.println(line);
                }
                p.waitFor();
                p.destroy();

    } catch (IOException e) {
        System.out.println("I/O error:" + e.getMessage());
    } catch (Exception e) {
        System.out.println("Error:" + e.getMessage());
    }
return null;
}
Reply all
Reply to author
Forward
0 new messages