I'm trying to start a process externally with Java and can't read anything from its InputStream.
If I'm starting a process with commands like "ls", "ps" or "kill" everything works fine. I can start the process and get information either on the InputStream or the ErrorStream of the Process.
If I try to use a command like "ftp" or "telnet" both InputStream and ErrorStream are blocking my program when trying to read. No information is passed through these streams at any time.
Can anyone explain the behavior? Is it just not possible with these commands or do I have an issue with my implementation?
String processName = _configuration.getProgramCommand().getCommand();
ProcessBuilder procBuilder = new ProcessBuilder(processName);
System.out.println("Starting process "+processName);
_proc = Runtime.getRuntime().exec(processName);// procBuilder.start();
if(!procBuilder.redirectErrorStream()) {
_errorWorker = new ProcessErrorWorker(_proc);
_errorWorker.start();
}
String proc_start_answer = _configuration.getNextCommand().getCommand();
System.out.println("Waiting for process answer '"+proc_start_answer+"'");
BufferedReader input = new BufferedReader(new InputStreamReader(_proc.getInputStream()));
String answer = "";
try {
System.out.println("inputstream ready: "+input.ready());
answer+=input.readLine();
System.out.println("process answer: "+answer);
input.close();
} catch(Exception e) {
System.out.print(e.getMessage());
}