Thanks for your reply. Actually in my Linux machine when I tried the original scenario I hit the issue that I have mentioned. Now when I check your
test program in windows without new window option it opens in the tab of the existing browser. But the waitfor call is not blocking. I am expecting the code to get blocked until the browser is killed. But it exits with 1 option and it means it is a problematic exit.
I have modified your code with what I did. Please let me know if you can think of any issue that is not making this call blocking. ( I am more interested in -new-window option)
import java.io.*;
public class StartFirefox{
public static void main(String args[]){
Runtime rt = Runtime.getRuntime();
try{
Process clientProcess = rt.exec(new String[] {"C:\\Program Files\\Mozilla Firefox\\firefox.exe","coderanch.com"});
StreamProcessor errorSt = new StreamProcessor(clientProcess.getErrorStream(), "ERROR");
StreamProcessor outputSt = new StreamProcessor(clientProcess.getInputStream(), "OUTPUT");
errorSt.start();
outputSt.start();
//Here actually the call should block
int exitcode = clientProcess.waitFor();
System.out.println(" Exit code "+exitcode);
} catch (Exception e){
e.printStackTrace();
}
}
static class StreamProcessor extends
Thread
{
InputStream is;
String type;
StreamProcessor(InputStream is, String type)
{
this.is = is;
this.type = type;
}
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">>>>" + line);
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}