Reputation: 9019
Is it possible to write error messages to the console from process that has been fired up? Normally we are used to using Console.Writeline() from within the console. The additional process (in another assembly) is designed to be operated by the console, and potentially also through a GUI.
However if we attach methods to event handlers (i.e. a callback), then Console.WriteLine is not working.
Currently using:
var thread=new Thread(someMethod);
thread.Start();
Subsequently, callbacks may get fired off, it's here that console messages go missing.
Upvotes: 2
Views: 5460
Reputation: 18106
Console.WriteLine()
should work as well.
Update:
If you want to capture output of some console application, please take a look at Capturing console output from a .NET application (C#).
Upvotes: 2
Reputation: 17584
Is this an external, compiled process, i.e. an executable?
If you're using the Process class to start the process, you might be looking for the Process.StandardOutput property, which will let you redirect the text normally written to the console to another stream.
Otherwise, can you clarify what kind of "process" you're talking about?
Upvotes: 1
Reputation: 12880
If you use the standard .NET tracing, you could configure a ConsoleTraceListener
through the app.config:
http://msdn.microsoft.com/en-us/library/system.diagnostics.consoletracelistener.aspx
This approach is explored more through this question: Redirect Trace output to Console
It's quite nice for diagnostic purposes as you mention. You can hook up text file writers, etc.
Upvotes: 1
Reputation: 56391
If you're concerned about two streams of messages co-mingling, why not use Console.Error.WriteLine()
? You can then redirect the error stream at execution to (for example) a file.
Upvotes: 2
Reputation: 62439
I'm not quite sure if I understand this correctly. Do you want to read from the standard output of a child process and write in the parent's console? Then you can use the Process.StandardOutput property to get a StreamReader
and start reading.
Upvotes: 1