Solved

Java process is failing when I attempt to capture stderr

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now