Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to capture Runtime.exec() output? doesn't seem to work?

963096Sep 19 2012 — edited Sep 20 2012
This is the first time I've used Runtime.exec();

Here's the code:
 Runtime rt = Runtime.getRuntime();
          
            process = rt.exec(jobCommand);

            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));

            String line=null;

            while((line=input.readLine()) != null) {
            	System.out.println("OUTPUT: " + line);
            }

            int exitVal = process.waitFor();

        } catch(Exception e) {
        	e.printStackTrace();
        }//end catch
as you can see, this is just copied and pasted out of the standard example for this method.

When it gets to the line:
while((line=input.readLine()) != null)

it doesn't read anything. However, when i run the SAME exact command from the windows CMD prompt i get a ton of output.

what am i doing wrong here?

thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2012
Added on Sep 19 2012
6 comments
799 views