Solved

Java process is failing when I attempt to capture stderr

Posted on 2011-02-23
3
592 Views
Last Modified: 2013-11-13
I am attempting to capture the stderr output of ffmpeg (see the sample code below). I have no problem capturing sdtout but the application hangs when I attempt to read stderr.

 try {
//banner is written to stderr
                 ProcessBuilder pb = new ProcessBuilder("c:\\bin\\ffmpeg.exe","-h");
                  
                  String line;
                  Process p = pb.start();
                  BufferedReader input =
                    new BufferedReader
                      (new InputStreamReader(p.getInputStream()));
                  while ((line = input.readLine()) != null) {
                    System.out.println(line);
                  }
                  BufferedReader input1 =
                          new BufferedReader
                            (new InputStreamReader(p.getErrorStream()));
                        while ((line = input1.readLine()) != null) {
                          System.out.println(line);
                        }
                 
                  input.close();
                }
                catch (Exception err) {
                  err.printStackTrace();
                }
             

I tried c# and it worked as expected

 see below


            string error;
            string output;
            ProcessStartInfo psi = new ProcessStartInfo(@"c:\signal\publisher\bin\ffmpeg.exe", "-h");
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError = true;
            System.Diagnostics.Process reg;
            psi.UseShellExecute = false;    
            reg = System.Diagnostics.Process.Start(psi);
            using (System.IO.StreamReader myOutput = reg.StandardOutput)
            { output = myOutput.ReadToEnd(); }
            using (System.IO.StreamReader myError = reg.StandardError)
            { error = myError.ReadToEnd(); }
            Console.WriteLine(error);
          //  Console.WriteLine(output);
            Console.ReadKey();

Any idea's why this doesn't work in java?
0
Comment
Question by:JonMny
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 34966378
you'll need to read it in a separate thread
http://helpdesk.objects.com.au/java/runtime-exec-locks-up
0
 
LVL 9

Author Comment

by:JonMny
ID: 34966743
0
 
LVL 92

Expert Comment

by:objects
ID: 34966844
should really find some time to update that code, its getting a little outdated.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 35
intellij error 2 17
hashmap order 17 36
collection output issue 9 36
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question