473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

StandardOutput.ReadLine() doesn't work until the app exits???

Ole
Hi,

I'm running a command line process from my C# application trying to catch
the output messages from the process into a textbox in my windows form. But
the text doesn't update (the ReadLine doesn't return) until the process
exits??? Any help is highly appreciated! The code is like this:

Process myProcess = new Process();
myProcess.StartInfo.FileName = Application.StartupPath +
"\\myCmdLine.exe";
myProcess.StartInfo.WorkingDirectory = Application.StartupPath;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
Thread processThread;
//.
//.
private void buttonStartProcess_Click(object sender, EventArgs e)
{
processThread = new Thread(new ThreadStart(runProcess));
processThread.IsBackground = true;
processThread.Start();
}

private void runProcess()
{
string data;
myProcess.Start();
while ((data = myProcess.StandardOutput.ReadLine()) != null)
{
UpdateTextBox(textBoxMessage, data); // this is a call to an
invoke function
}
}

Thanks,
Ole
Mar 6 '07 #1
6 12741
Hi,
>
I'm running a command line process from my C# application trying to
catch the output messages from the process into a textbox in my
windows form. But the text doesn't update (the ReadLine doesn't
return) until the process exits??? Any help is highly appreciated! The
code is like this:
while ((data = myProcess.StandardOutput.ReadLine()) !=
null)
Are you sure you want Standard *Output*, and not StandardInput (or whatever
it's called)?

Hans Kesting
Mar 6 '07 #2
Many things can be the cause of this.
ReadLine returns after it gets CR/LF that it might not be seeing (When the
child process closes, it closes the stream too and thus the ReadLine
completes anyway).
The myCmdLine.exe's console buffer could not be filled enough until exit
(normal buffer is 4k).
If the myCmdLine.exe is yours, you could add some Console.Out.Flush() calls.
Also be aware that synchronous reading from child process can produce
deadlocks. You'd better of with BeginOutputReadLine (check documentation for
that) or, use Read() or ReadToEnd().
"Ole" <ol*@blabla.comha scritto nel messaggio
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,

I'm running a command line process from my C# application trying to catch
the output messages from the process into a textbox in my windows form.
But the text doesn't update (the ReadLine doesn't return) until the
process exits??? Any help is highly appreciated! The code is like this:

Process myProcess = new Process();
myProcess.StartInfo.FileName = Application.StartupPath +
"\\myCmdLine.exe";
myProcess.StartInfo.WorkingDirectory = Application.StartupPath;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
Thread processThread;o
//.
//.
private void buttonStartProcess_Click(object sender, EventArgs e)
{
processThread = new Thread(new ThreadStart(runProcess));
processThread.IsBackground = true;
processThread.Start();
}

private void runProcess()
{
string data;
myProcess.Start();
while ((data = myProcess.StandardOutput.ReadLine()) != null)
{
UpdateTextBox(textBoxMessage, data); // this is a call to
an invoke function
}
}

Thanks,
Ole


Mar 6 '07 #3
Ole
Thanks!

I couldn't get it to work no matter what I did, so i guess that the command
line application doesn't output the stream until it has finished. I'll have
to live with that a command window opens and closes during my program run.

Thanks
Ole
"Laura T." <LT@NOWHERE.COMwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
Many things can be the cause of this.
ReadLine returns after it gets CR/LF that it might not be seeing (When the
child process closes, it closes the stream too and thus the ReadLine
completes anyway).
The myCmdLine.exe's console buffer could not be filled enough until exit
(normal buffer is 4k).
If the myCmdLine.exe is yours, you could add some Console.Out.Flush()
calls.
Also be aware that synchronous reading from child process can produce
deadlocks. You'd better of with BeginOutputReadLine (check documentation
for that) or, use Read() or ReadToEnd().
"Ole" <ol*@blabla.comha scritto nel messaggio
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Hi,

I'm running a command line process from my C# application trying to catch
the output messages from the process into a textbox in my windows form.
But the text doesn't update (the ReadLine doesn't return) until the
process exits??? Any help is highly appreciated! The code is like this:

Process myProcess = new Process();
myProcess.StartInfo.FileName = Application.StartupPath +
"\\myCmdLine.exe";
myProcess.StartInfo.WorkingDirectory = Application.StartupPath;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardOutput = true;
Thread processThread;o
//.
//.
private void buttonStartProcess_Click(object sender, EventArgs e)
{
processThread = new Thread(new ThreadStart(runProcess));
processThread.IsBackground = true;
processThread.Start();
}

private void runProcess()
{
string data;
myProcess.Start();
while ((data = myProcess.StandardOutput.ReadLine()) != null)
{
UpdateTextBox(textBoxMessage, data); // this is a call to
an invoke function
}
}

Thanks,
Ole



Mar 8 '07 #4
Hans Kesting wrote:
>I'm running a command line process from my C# application trying to
catch the output messages from the process into a textbox in my
windows form. But the text doesn't update (the ReadLine doesn't
return) until the process exits??? Any help is highly appreciated! The
code is like this:
>while ((data = myProcess.StandardOutput.ReadLine()) !=
null)

Are you sure you want Standard *Output*, and not StandardInput (or
whatever it's called)?
The child process's output is the parent process's input.

Arne
Mar 17 '07 #5
Ole wrote:
I couldn't get it to work no matter what I did, so i guess that the command
line application doesn't output the stream until it has finished. I'll have
to live with that a command window opens and closes during my program run.
Flush should fix it.

Note that while output traditionally is buffered then error
is not.

Sometimes it is just easy to write to error.

Arne
Mar 17 '07 #6
Ole
Flush should fix it.
>
Note that while output traditionally is buffered then error
is not.
Thanks, but I don't have control over the command line application - it's a
third party one.

BR
Ole
Mar 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Station Media | last post by:
Hi, here my problem, i use stored procedure in ACCESS database(latest version), and i would like to use this procedure but it doesnt work, do you know why ? Procedure: PARAMETERS MyField Text...
3
by: Clouds | last post by:
Hi ! How do I add the dynamic event handler for a dropdownlist present in the itemtemplate of a datalist !! I am doing it in the itemdatabound event of the datalist but it doesnt work... I am...
0
by: Juna | last post by:
I have been working in vs2003, but now started to work in vs2005 but the problem, I have simple web application not website, which work i mean open in browser when we press F5 or run the...
1
Digital Don
by: Digital Don | last post by:
I am writing a program for Peg solitaire... To check for no repetition of previous states I use a Set for storage of Board states.. The pronblem is when I declare the set as type char i.e. set...
3
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it...
1
by: Dany13 | last post by:
hi all. i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for...
20
by: Hush | last post by:
Hi, The following code works fine in IE7 but FF returns with an error: Access denied to achieve the property Element.firstChild. In this line: nodes = xmlDoc.documentElement.childNodes; My...
9
by: AGP | last post by:
I've been scratching my head for weeks to understand why some code doesnt work for me. here is what i have: dim sVal as string = "13.2401516" dim x as double x = sVal debug.writeline ( x)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.