开发者

Weird problem getting input from getInputStream

Here's my code:

    Runtime re = Runtime.getRuntime();
    BufferedReader output = null;    

    try{
            Process cmd = re.exec("jav开发者_StackOverflow中文版a -jar myProg.jar " + myArgument); 
            output =  new BufferedReader(new InputStreamReader(cmd.getInputStream()));
        }

    catch (Exception e){
            e.printStackTrace();
    }

   String line;
   while ((line = output.readLine()) != null)
   {
    //process line
   }

When debugging this code snippet, I find that when reading each line from output, it skips certain lines.

If i run this myProg.jar from command line, the text that's seen on my command line is not 100% the same as what I get when I process the output from inside my java program!

What could cause this? The output is all text.


You only appear to be reading standard out, whereas you may be getting output on standard error as well. I would read both.

Note that you need to read both streams concurrently, to avoid blocking. See this answer for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜