2006-11-19, 08:50 AM 
	
	
	
		In my "MVPRecoder" app, I do something similar....
One other thing I have done is start seperate "stdout" and "stderr" reader-threads to check / evaluate what's written to stdout/stderr...
Here's the (C#) code:
And here's the code for the stdout/stderr reader class:
the "\b\b"'s are interpreted by the console on WinX to delete previous character on the console..... That way you can make a nice progress-indicator (from the command-line anyway).
	
	
	
One other thing I have done is start seperate "stdout" and "stderr" reader-threads to check / evaluate what's written to stdout/stderr...
Here's the (C#) code:
Code:
            Process proc = new Process();
            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = recode_path;
            proc.StartInfo.Arguments = command_line;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;
            
            proc.Start();
            StdReader cOut = new StdReader();
            cOut.theReader = proc.StandardOutput;
            Thread tOut = new Thread(new ThreadStart(cOut.StdOutReader));
            StdReader cErr = new StdReader();
            cErr.theReader = proc.StandardError;
            Thread tErr = new Thread(new ThreadStart(cErr.StdErrReader));
            tOut.Start();
            tErr.Start();
            proc.WaitForExit();
            tOut.Abort();
            tErr.Abort();And here's the code for the stdout/stderr reader class:
Code:
    class StdReader
    {
        public StreamReader theReader;
        public string data;
        
        public void StdErrReader() {
            
            try {
                while (true) {
                    data = theReader.ReadLine();
                    // Ignore all standard errors...
                    if (!data.StartsWith("WARNING"))
                        if (!data.StartsWith("ERROR: SCR:"))
                            if (!data.StartsWith("1 duplicate frame(s)"))
                                if (data.IndexOf("buffer underflow") == 0)
                                    Console.WriteLine(data);
                }
            } catch {}
        } 
        public void StdOutReader() {
            
            try {
                while (true) {
                    data = theReader.ReadLine();
                    if (data.StartsWith("Pos:")) {
                        Console.Write("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
                        Console.Write(data.Substring(4, 28).TrimStart());
                     }
                }
            } catch {}
        }    
    }
//Ton
	
 



 .
. alibert's solution is startlingly elegant (and certainly the simplest - it passes the "Ockham's Razor" test). If you needed to know when the process had completed (as I do), you could just check Process.HasExited from time to time, I guess.
  alibert's solution is startlingly elegant (and certainly the simplest - it passes the "Ockham's Razor" test). If you needed to know when the process had completed (as I do), you could just check Process.HasExited from time to time, I guess.