Writing the output from console applications to text file

Console applications provide a quick and easy way (and also a little bit dirty) to test or fix parts of your application. It enables you to focus on the business logic rather than the GUI. Sometimes the output to the window is quite large - larger than the console window can show. In those cases you want to be able to persist the output to text files. In this post, I’ll show you how to do this. It is really easy to achieve this, just follow these steps sequentially. Note: you can tailor this process to the way you want to, this is merely a possible way how to do it. If you are more comfortable of writing code, that is equally as well but it’ll require more effort. Nonetheless, here’s how you can do it:

  1. Navigate to the folder where your executable (console application bin folder) is located.
  2. Enter “CMD” in the window, as shown in the screenshot below:cmd
  3. Next the command window will pop up with the current directory already targeting the correct folder.
  4. Now run this command - replace the placeholders by your values”
NameOfYourApplication.exe "Parameter 1" "Parameter 2" "Parameter X" > "NameOfYourLogfile.YourExtension"

Here’s an example: cmdLog All output that otherwise would be printed in the window is now transferred to the log file. That’s all there is to say about this subject!

Written on June 9, 2015