I don't know if it is possible, but thougt of giving it a try.
I am executing a small perl code within my java program like this
private void executePerlCode() {
Process process;
ProcessBuilder processBuilder;
BufferedReader bufferedReader = null;
try {
// this line is used to execute the perl program
processBuilder = new ProcessBuilder("perl", "D:\\test\\loop.pl");
process = processBuilder.start();
// To get the output from perl program
bufferedReader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line;
StringBuffer str = new StringBuffer();
while ((line = bufferedReader.readLine()) != null) {
str.append(line);
System.out.println(line);
}
// process.waitFor();
// Set the output on the textfield
// jTextArea1.setText(str.toString());
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
} finally {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
And my perl code is
for (my $i=0; $i <= 9; $i++) {
print "$i\n";
sleep(1);
}
I am able to get the output of perl program in my java program. But I want the perl code to give continuous output to java code. Like this, when the loop in perl prints value of 'i' for first time, I should be able to get that value in Java code. So that I can continuously update my Java UI according to the process going on in Perl code.
continuousyou'll need to write some perl to talk to java, on maybe a named pipe or some common store.process.waitFor();inside your code (which waits until the process has terminated).process.waitFor(), still not working as expected.