472,986 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Console app output inside a winform app

I have created a console app that simply prints out a message a couple
times, then exits, here is the code:
<code>
for(int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
Console.WriteLine(String.Format("Sleeping...{0}", i));
}
Console.WriteLine("Done!");
</code>
Then in my winform app, I have this bit of code that creates a new Process;
<code>
public void Build()
{
String commandLine = "";
commandLine =
@"C:\PMDRepository\Tools\DQ_Tools\FirmwareEditor\C onsoleTest\bin\Debug\Conso
leTest.exe";

// execute
Process process = new Process();
process.EnableRaisingEvents = true;
process.StartInfo.UseShellExecute = false;
process.Exited += new EventHandler(ProcessExited);
process.StartInfo.FileName = commandLine;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput= true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

try
{
process.Start();
m_working = true;
string line = string.Empty;
string previousReadLine = string.Empty;
while(process.StandardOutput.Peek() > -1)
{
line = process.StandardOutput.ReadLine();
if(line != previousReadLine)
{
previousReadLine = line;
m_log.LogRaw("IARBuilder:\t{0}", line);
}
}
}
catch(Exception ex)
{
m_log.LogError(ex.Message);
}
}
</code>
in the while(process.StandardOutput.Peek() > -1)) loop, execution enters
that once, but never again. I'm not sure what's happening, but it seems
like it captures the output once, then doesn't try to read it again. Anyone
know the correct way to do this?

Thanks for any help,
Steve
Dec 9 '05 #1
2 4701
I just noticed something interesting.. if I set a breakpoint on line:
line = process.StandardOutput.ReadLine();
and then use F10 to step through the loop, then I can see that each line is
being read and indeed printed to the UI, but if there is no breakpoint only
one line is printed out.

maybe Peek() isn't the best thing to be checking...
"Steve" <ss*@sss.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
I have created a console app that simply prints out a message a couple
times, then exits, here is the code:
<code>
for(int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
Console.WriteLine(String.Format("Sleeping...{0}", i));
}
Console.WriteLine("Done!");
</code>
Then in my winform app, I have this bit of code that creates a new Process; <code>
public void Build()
{
String commandLine = "";
commandLine =
@"C:\PMDRepository\Tools\DQ_Tools\FirmwareEditor\C onsoleTest\bin\Debug\Conso leTest.exe";

// execute
Process process = new Process();
process.EnableRaisingEvents = true;
process.StartInfo.UseShellExecute = false;
process.Exited += new EventHandler(ProcessExited);
process.StartInfo.FileName = commandLine;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput= true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

try
{
process.Start();
m_working = true;
string line = string.Empty;
string previousReadLine = string.Empty;
while(process.StandardOutput.Peek() > -1)
{
line = process.StandardOutput.ReadLine();
if(line != previousReadLine)
{
previousReadLine = line;
m_log.LogRaw("IARBuilder:\t{0}", line);
}
}
}
catch(Exception ex)
{
m_log.LogError(ex.Message);
}
}
</code>
in the while(process.StandardOutput.Peek() > -1)) loop, execution enters
that once, but never again. I'm not sure what's happening, but it seems
like it captures the output once, then doesn't try to read it again. Anyone know the correct way to do this?

Thanks for any help,
Steve

Dec 9 '05 #2
Well, I solved part of this issue, by changing the line:
<code>
while(process.StandardOutput.Peek() > -1)
</code>
to:
<code>
while(m_working == true)
</code>

I was able to get my test console application to work fine, it spit out the
messages just like I would expect.
When I switched over to my real command line app that I want to use, I still
get odd output. When I execute the comman line in a shell, I get this
output:

<console output>
C:\>"C:\Program Files\IAR Systems\Embedded Workbench
4.0\common\bin\iarbuild.exe"
"C:\PMDRepository\IF_Firmware\DuetQuartet.ewp" -build Release
IAR Command Line Build Utility V4.4.2
Copyright 2002-2004 IAR Systems. All rights reserved.
Rebuilding configuration: DuetQuartet - Release
0 file(s) deleted.
ADC.c
Audible.c
Display.c
Flash.c
Ints.s43
KS0066U.c
Key.c
Ports.c
Protocol.c
SPI.c
Timers.c
UI.c
main.c
pmd_strlen.c
Linking
Total number of errors: 0
Total number of warnings: 2
</console output>

When I run the same command line with my Process object, I get this output
in my GUI:
<output>
Copyright 2002-2004 IAR Systems. All rights reserved.
IAR Command Line Build Utility V4.4.2
</output>

So... why aren't I seeing everything else? Any ideas what I could check
for?
"Steve" <ss*@sss.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
I just noticed something interesting.. if I set a breakpoint on line:
line = process.StandardOutput.ReadLine();
and then use F10 to step through the loop, then I can see that each line is being read and indeed printed to the UI, but if there is no breakpoint only one line is printed out.

maybe Peek() isn't the best thing to be checking...
"Steve" <ss*@sss.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...
I have created a console app that simply prints out a message a couple
times, then exits, here is the code:
<code>
for(int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
Console.WriteLine(String.Format("Sleeping...{0}", i));
}
Console.WriteLine("Done!");
</code>
Then in my winform app, I have this bit of code that creates a new

Process;
<code>
public void Build()
{
String commandLine = "";
commandLine =

@"C:\PMDRepository\Tools\DQ_Tools\FirmwareEditor\C onsoleTest\bin\Debug\Conso
leTest.exe";

// execute
Process process = new Process();
process.EnableRaisingEvents = true;
process.StartInfo.UseShellExecute = false;
process.Exited += new EventHandler(ProcessExited);
process.StartInfo.FileName = commandLine;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput= true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

try
{
process.Start();
m_working = true;
string line = string.Empty;
string previousReadLine = string.Empty;
while(process.StandardOutput.Peek() > -1)
{
line = process.StandardOutput.ReadLine();
if(line != previousReadLine)
{
previousReadLine = line;
m_log.LogRaw("IARBuilder:\t{0}", line);
}
}
}
catch(Exception ex)
{
m_log.LogError(ex.Message);
}
}
</code>
in the while(process.StandardOutput.Peek() > -1)) loop, execution enters
that once, but never again. I'm not sure what's happening, but it seems
like it captures the output once, then doesn't try to read it again.

Anyone
know the correct way to do this?

Thanks for any help,
Steve


Dec 9 '05 #3

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

Similar topics

2
by: Boba | last post by:
Hi, I'm programming a WinForm application. I would like to enter commands that will send output that will help me to locate bugs in the future. I know that there is a way to send output by...
4
by: Ron Vecchi | last post by:
I am looking for a way to write xml data to file from a macromedia flash executable. I was thinking about haveing flash call a console app with a parameter...which is the xml string to write to...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
2
by: Schorschi | last post by:
Ok, I have my own console class that lets me allocate a console, free it, etc. in my windows vb .net application, hell it even hides the cursor, set colors, etc. But the one thing I want to do is...
4
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; When my ASP.NET app is running on IIS, where does the Console.Out.WriteLine("hi there"); output go? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
4
by: Dinsdale | last post by:
I am writing a small console application that runs fine unless I am re- directing the output to a file (i.e. c:\ app.exe >>output.txt) . I have determined that the issue is caused by the...
6
by: None | last post by:
Hello, my app is written in C#. Given an app file path (e.g. e:\abc.exe), how can I determine if it's a winform app or a console one. (note: abc.exe can be either a native exe or a .net one)
1
by: mquincey | last post by:
One of the features offered by .NET 2.0 is the use of the TraceSource class. In an attempt to demonstrate its use, I wanted to run my test under the following conditions: 1. Use TraceSource class...
27
by: CarlosMB | last post by:
Hello, I am writing code that uses a DLL which is supposed to print to console some useful information but for some reason it is not doing so. The environment is a bit complex to explain but...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.