Reading console output for Process - PLS HELP

M

MuZZy

Hi,

I just wonder if anybody could help me with this:
I have a WinForms app which by pressing a button creates a process invoking lame.exe to convert a wave file to mp3.
The process is launcghed in a separate thread.
I need to be able to read the console to update the progressBar on the form with current percentage of conversion.
The problem is that it returns blank if i read from standard output

Here's the code:

// ================== CODE START =============================
string lame_param = String.Format(" -b32 -mm {0} {1}", WavFileToEnc, Mp3FileName);
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo("lame.exe", lame_param);
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
//psi.CreateNoWindow = true;
p.StartInfo = psi;
try
{
p.Start();
StreamReader reader = p.StandardOutput;
string s = "";
while (!p.HasExited)
s += reader.ReadLine();
// I ALSO TRIED s = reader.ReadToEnd(); - same result
p.WaitForExit();
}
finally
{
p.Close();
}
// ================== CODE END ===============================

The value of string "s" stays blank for all the time, but lame obviousely makes an output

Any ideas would be highly appreciated!

Thank you,
Andrey
 
J

Jon Skeet [C# MVP]

MuZZy said:
I just wonder if anybody could help me with this:
I have a WinForms app which by pressing a button creates a process
invoking lame.exe to convert a wave file to mp3.
The process is launcghed in a separate thread.
I need to be able to read the console to update the progressBar on
the form with current percentage of conversion.
The problem is that it returns blank if i read from standard output

You should try reading from (and redirecting) StandardError as well. It
could be that lame is outputting on that.

Just as an aside, I'd recommend using a StringBuider rather than
repeated string concatenation.
 
M

MuZZy

Jon said:
You should try reading from (and redirecting) StandardError as well. It
could be that lame is outputting on that.

Thanks a lot, that worked!
Just as an aside, I'd recommend using a StringBuider rather than
repeated string concatenation.

Yeap, you right, i keep trying to start using stringbuilder ever since java :)
Ahhhh


Thank you,
Andrey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top