Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Console app question

Console app question

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studiolearning
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krista Crawley Archer
    wrote on last edited by
    #1

    I know this is beginner-level, but how can I write a console app with Visual Studio, run the app and have the output redirected to the Visual Studio output window? If I can't do that, is there another means of pausing the application without calling a getchar() type function? bye bye, KLC

    J V 2 Replies Last reply
    0
    • K Krista Crawley Archer

      I know this is beginner-level, but how can I write a console app with Visual Studio, run the app and have the output redirected to the Visual Studio output window? If I can't do that, is there another means of pausing the application without calling a getchar() type function? bye bye, KLC

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      You can use the trace functions to get your text to the output window. System.Diagnostics.Trace I don't think there is one-line method of changing all System.Console.WriteLine's to use the output window. But you could write a class that implements/extends System.IO.TextWriter (using the Trace class as your backend) then use System.Console.SetOut, passing in an instance of your new class. HTH, James Sonork ID: 100.11138 - Hasaki

      K 1 Reply Last reply
      0
      • J James T Johnson

        You can use the trace functions to get your text to the output window. System.Diagnostics.Trace I don't think there is one-line method of changing all System.Console.WriteLine's to use the output window. But you could write a class that implements/extends System.IO.TextWriter (using the Trace class as your backend) then use System.Console.SetOut, passing in an instance of your new class. HTH, James Sonork ID: 100.11138 - Hasaki

        K Offline
        K Offline
        Krista Crawley Archer
        wrote on last edited by
        #3

        Thanks James, but both methods requires a lot of changing of code that doesn't need to be changed. I was hoping for at least a way in Visual Studio to route all Writelines to the output window. Oh well. Thanks anyway. bye bye, KLC

        J 1 Reply Last reply
        0
        • K Krista Crawley Archer

          Thanks James, but both methods requires a lot of changing of code that doesn't need to be changed. I was hoping for at least a way in Visual Studio to route all Writelines to the output window. Oh well. Thanks anyway. bye bye, KLC

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          I didn't look into it too much when I replied (was busy putting the finishing touches on an article). Here's a class that'll do what you want :)

          using System;
          using System.Diagnostics;

          namespace ConsoleRerouter
          {
          /// /// Summary description for OutputToTrace.
          ///
          public class OutputToTrace : System.IO.TextWriter
          {
          public OutputToTrace()
          {

          	}
          
          	public override void Write(char c)
          	{
          		Trace.Write(c, "Console");
          	}
          
          	public override void WriteLine(string line)
          	{
          		Trace.WriteLine(line, "Console");
          	}
          	
          	private System.Text.Encoding enc = new System.Text.ASCIIEncoding();
          	public override System.Text.Encoding Encoding
          	{
          		get
          		{
          			return enc;
          		}
          	}
          }
          

          }

          If you do anything really vigorous you'll have to add more calls to Trace.Write/WriteLine, but it'll do the deed as it is right now. Use it like System.Console.SetOut(new ConsoleRerouter.OutputToTrace()); It worked great in my simple test (output everything that was typed in) Enjoy, James Sonork ID: 100.11138 - Hasaki

          1 Reply Last reply
          0
          • K Krista Crawley Archer

            I know this is beginner-level, but how can I write a console app with Visual Studio, run the app and have the output redirected to the Visual Studio output window? If I can't do that, is there another means of pausing the application without calling a getchar() type function? bye bye, KLC

            V Offline
            V Offline
            Valer BOCAN
            wrote on last edited by
            #5

            Run the program by pressing CTRL+F5. The command-line window will request you to press a key before terminating.:-O

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups