The Artima Developer Community
Sponsored Link

Java Answers Forum
java with maple help (runtime)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
jayakumar perumal

Posts: 16
Nickname: jai
Registered: Feb, 2002

java with maple help (runtime) Posted: Mar 7, 2003 3:27 PM
Reply to this message Reply
Advertisement
hi
iam trying to execute maple using a servlet and iam getting a error can anyone help me. iam trying to make maple web enabled. can anyone help me know how to call other programs from java.... i have my sample file that gives a error.



import java.io.*;
import java.util.*;

public class Maple {
private Process process; // Used to call Maple.
private OutputStream maple_input;
private BufferedReader maple_output;
public Maple() throws IOException {
this.process = Runtime.getRuntime().exec("cmaple -q");
// <-- change cmaple to maple if running under unix.
this.maple_input = process.getOutputStream();
this.maple_output = new BufferedReader(new
InputStreamReader(process.getInputStream()));
}

// Close the Maple session:
public void close() throws IOException {
String quit = "quit\n";
maple_input.write(quit.getBytes());
maple_input.flush();
try{ process.waitFor(); } catch(InterruptedException ex) {}
}

// Execute a given command 'cmd' and write the results to 'out'.
public synchronized void exec(String cmd, PrintWriter out) throws
IOException {
// execute user's command:
String Cmd = cmd + ";\n";
maple_input.write( Cmd.getBytes() );
maple_input.flush();

// Log the command:
System.out.println("> "+ cmd + ";");

// To detect the end of Maple's user output, pass the follwing
//'unique' command to Maple:
String terminator_cmd = "JAVA:END OF A MAPLE COMMAND IS HERE";
maple_input.write( ("printf(`" + terminator_cmd +"\\n`):\n").getBytes() );
maple_input.flush();

// Next, read the output, line-by-line, until terminator_cmd is read:
String s;
while(true) {
s = maple_output.readLine();
if (s.indexOf(terminator_cmd) != -1 ) {
break;
}
if (out != null) {
out.println(s);
}
}
}
}


Maple maple = new Maple();
maple.exec("2+2", out);
maple.close();

Topic: J++ error.... Previous Topic   Next Topic Topic: Question about GUI component

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use