Friday, May 28, 2010

Visual Studio Console Application simple output to file.

There is a very simple way to write output from a console application to a textfile.

Just put >> output.txt when executing file.

namespace Simple
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < args.Count(); i++)
            {
                Console.WriteLine(string.Format("arg[{0}]: {1} ",i,args[i]));
            }
        }
    }
}
After compile you have an "simple.exe" file. If you want to get output to a file you can just type in simple.exe >> output.txt (>> appends to file and > creates a new)

Easy. You can also use the same method to write any output to file ie. when compiling from command line.

No comments: