Solved

Java process is failing when I attempt to capture stderr

Posted on 2011-02-23
3
593 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

763 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