Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java process is failing when I attempt to capture stderr

Posted on 2011-02-23
3
Medium Priority
?
597 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Make the most of your online learning experience.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Six Sigma Control Plans

772 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