0

I am running a c++ program (makefile) as a background process using Processbuilder from my java Program. I am capturing the values displayed in my cmd prompt using .getInputStream and displaying in my console (IDE) .

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

            String line;
    try {
       while((line=input.readLine()) != null) {

            System.out.println(line);

This works well. Suppose if i make some error in one of my c++ file and when i try to run the makefile it is not capturing the error message. On using "cmd.exe","start" i can view the error in cmd prompt but it is not displayed in the console(IDE) .

May i know what i should do to get the error message displayed.

1) System.err and printstream could be the solution for this ? if it so could you be please show me a sample piece of code. Thanks in advance

sreram
  • 99
  • 2
  • 9
  • Did you use [ProcessBuilder#redirectError](http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#redirectError(java.lang.ProcessBuilder.Redirect))? – MadProgrammer Mar 30 '13 at 09:54
  • Thanks MadProgrammer. – sreram Mar 30 '13 at 10:18
  • if it is an error i can get it through redirectError as menthioned by you. I can get the output through .getInputStream. If i run an exe at background its processing is not captured either by errorstream or inputstream. How can i get that? – sreram Mar 30 '13 at 10:40
  • If you use redirectError, the error output will be redirected to the InputStream. Instead of using BufferedReader#readLine, try reading each character individually – MadProgrammer Mar 30 '13 at 10:46
  • Try taking a look at [this example](http://stackoverflow.com/questions/15286042/im-not-getting-any-output-and-probably-the-machine-hangs-with-the-code/15286128#15286128) – MadProgrammer Mar 30 '13 at 10:49

1 Answers1

2

Process has .getErrorStream() or you can use ProcessBuilder's .redirectErrorStream() as mentioned by MadProgrammer's comment and this SO Question: Java Process with Input/Output Stream

Community
  • 1
  • 1
SeKa
  • 1,825
  • 12
  • 7
  • @sreram if you like someone's answer, or it solved your problem, then you should upvote it and/or mark it best answer. Comments do not apply, but you can still give them an up. – Cardinal System Apr 26 '17 at 20:58