473,383 Members | 1,862 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,383 software developers and data experts.

How to get Conole output information in my winform program?

I use some "Console.WriteLine(some strings here)" to
display some
debug information in my winform program.
How can I get the information in my programe or same them
in a text file ?

Nov 15 '05 #1
3 3687

"Liren Zhao" <li*******@tom.com> schreef in bericht
news:00****************************@phx.gbl...
I use some "Console.WriteLine(some strings here)" to
display some
debug information in my winform program.
How can I get the information in my programe or same them
in a text file ?


I'm not saying the following is a clean implementation but it works. The
code depends on the value of the String output. If output is empty all data
is written to the console otherwise the console is redirected to the file
specified by output :

/*******************************************/
/* Output redirector */
StreamWriter sw = null ;
TextWriter tmp = Console.Out;
if (output != "")
{
tmp = Console.Out;
FileStream fs = new FileStream(output, FileMode.OpenOrCreate,
FileAccess.Write);
sw = new StreamWriter(fs);
Console.SetOut(sw);
}

// do your work just as normal
Console.WriteLine("redirection test");

/* Output redirector clean up */
if (output != "")
{
Console.SetOut(tmp);
sw.Close();
}
/*******************************************/

Yves
Nov 15 '05 #2
Thanks for your replay.
I'm a jackaroo in c#,would you give me a full code?

And what is output in your code?

"phoenix" <pa******@skynetWORK.be> дÈëÏûÏ¢
news:#C**************@TK2MSFTNGP11.phx.gbl...

"Liren Zhao" <li*******@tom.com> schreef in bericht
news:00****************************@phx.gbl...
I use some "Console.WriteLine(some strings here)" to
display some
debug information in my winform program.
How can I get the information in my programe or same them
in a text file ?

I'm not saying the following is a clean implementation but it works. The
code depends on the value of the String output. If output is empty all

data is written to the console otherwise the console is redirected to the file
specified by output :

/*******************************************/
/* Output redirector */
StreamWriter sw = null ;
TextWriter tmp = Console.Out;
if (output != "")
{
tmp = Console.Out;
FileStream fs = new FileStream(output, FileMode.OpenOrCreate,
FileAccess.Write);
sw = new StreamWriter(fs);
Console.SetOut(sw);
}

// do your work just as normal
Console.WriteLine("redirection test");

/* Output redirector clean up */
if (output != "")
{
Console.SetOut(tmp);
sw.Close();
}
/*******************************************/

Yves

Nov 15 '05 #3
"Liren Zhao" <li*******@tom.com> schreef in bericht
news:eL**************@TK2MSFTNGP12.phx.gbl...
Thanks for your replay.
I'm a jackaroo in c#,would you give me a full code?

It is a full code ... At the bottom of this message you'll find it inside a
console application but nothing much changed. Just comment out the output
definition you don't want to use to test both cases.
And what is output in your code?

A String like i stated just above the code in the previous message ...
"phoenix" <pa******@skynetWORK.be> дÈëÏûÏ¢
news:#C**************@TK2MSFTNGP11.phx.gbl...

"Liren Zhao" <li*******@tom.com> schreef in bericht
news:00****************************@phx.gbl...
I use some "Console.WriteLine(some strings here)" to
display some
debug information in my winform program.
How can I get the information in my programe or same them
in a text file ?


using System;
using System.IO;
namespace softtech.redirection
{
class redir
{
[STAThread]
static void Main(string[] args)
{
String output = @"c:\test.txt"; // output redirection to the file
//String output = ""; // normal output to stdout

StreamWriter sw = null ;
TextWriter tmp = Console.Out;

if (!output.Equals(""))
{
tmp = Console.Out;
FileStream fs = new FileStream(output,
FileMode.OpenOrCreate,FileAccess.Write);
sw = new StreamWriter(fs);
Console.SetOut(sw);
}

// do your work just as normal
// the program will write to the correct spot
Console.WriteLine("redirection test");

/* Output redirector clean up */
if (!output.Equals(""))
{
Console.SetOut(tmp);
sw.Close();
}
}
}
}
Nov 15 '05 #4

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

Similar topics

3
by: jdionne | last post by:
I have a WInform app that runs a DTS. When I developed it on the SQL box and executed it, it ran fine. I used the Trusted connection parameter for the DTS. I don't want to use passwords. I...
5
by: Frank Meng | last post by:
Hi. I got some sample codes from Fig 10 of http://msdn.microsoft.com/msdnmag/issues/03/05/Real-WorldXML/default.aspx .. If I read an XML file like: <test> <good>1</good> </test> The output...
1
by: Ollie Riches | last post by:
Does anyone know a way to create a winform window that has similiar functionality to the 'Output' window in VS .Net - i.e. that basically acts like a console window but is proper MDI child of the...
3
by: Scott Meddows | last post by:
I have a group of objects that I want to be able to echo information (Console.writeline in the NEw(), Add(), etc). The objects will be used in a service and in my test application (Winform). ...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
2
by: Steve | last post by:
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);...
4
by: wertqt | last post by:
hi all, i have a project in hand on viewing of information from MS Acess. Im using VS 2005 C#.NET to write this program. im stuck in this problem on writing codes to show graphs in a windows form....
0
by: Tom | last post by:
Hi all -- this is my first posting here and I want to start by saying thank you to all the responders. I have done some searching and reading and have learned a few things I didn't even know to...
14
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.