Solved

Java process is failing when I attempt to capture stderr

Posted on 2011-02-23
3
586 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This is an explanation of a simple data model to help parse a JSON feed
The viewer will learn how to implement Singleton Design Pattern in Java.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

773 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