I want to use a linux command line tool from my Java program. I start the program and get the output using the Process class (http://download.oracle.com/javase/6/docs/api/java/lang/Process.html):
/* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Process proc = Runtime.getRuntime().exec("octave");
BufferedReader reader =
new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader errorReader =
new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedWriter writer =
new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
int c;
while((c = proc.getInputStream().read()) != -1) {
System.out.print((char)c);
}
System.out.println("End");
}
I get the following output:
GNU Octave, version 3.0.5 Copyright
(C) 2008 John W. Eaton and others.
This is free software; see the source
code for copying conditions. There is
ABSOLUTELY NO WARRANTY; not even for
MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. For details, type
`warranty’.Octave was configured for
“i486-pc-linux-gnu”.Additional information about Octave is
available at http://www.octave.org.Please contribute if you find this
software useful. For more information,
visit
http://www.octave.org/help-wanted.htmlReport bugs to (but
first, please read
http://www.octave.org/bugs.html to
learn how to write a helpful report).For information about changes from
previous versions, type `news’.
The strange thing is the normal output if I run octave in the Terminal is the following:
:~/workspace/Console/src/c$ octave
GNU Octave, version 3.0.5
Copyright (C) 2008 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty’.Octave was configured for “i486-pc-linux-gnu”.
Additional information about Octave is available at http://www.octave.org.
Please contribute if you find this software useful.
For more information, visit http://www.octave.org/help-wanted.htmlReport bugs to (but first, please read
http://www.octave.org/bugs.html to learn how to write a helpful report).For information about changes from previous versions, type `news’.
octave:1>
So the characters in the line where the input is requested are not sent in my input stream. Why? Isn’t it possible to detect whether input is requested?
Thanks for your answers!
Heinrich
I could finally solve the problem: Under Linux, use Octave with the –interactive and eventually the –no-line-editing optionand it worked 🙂
Heinrich