public class Foo() { public Process runProcess() throws IOException { String execCmd = getTargetAlgorithmExecutionCommand(); System.out.println(execCmd); Process proc = Runtime.getRuntime().exec(execCmd,null, new File(execConfig.getAlgorithmExecutionDirectory())); return proc; } public void processRunLoop(Scanner procIn) { while(procIn.hasNext()) { String line = procIn.nextLine(); processLine(line); } } @Override public void run() { Process proc; proc = runProcess(); Scanner procIn = new Scanner(proc.getInputStream()); processRunLoop(procIn); } }