Why Does Console.WriteLine() Not Write to Command Window?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joey.powell@topscene.com

    Why Does Console.WriteLine() Not Write to Command Window?

    I have a windows form app in C# in VS2005. In the "program.cs " file, I
    take some command line arguments and use "Console.WriteL ine("fsdfsd")
    to give feedback to users. When I step through the program, the code
    block is executing, but no text is written to the command line.

    What might be causing this?

  • Marc Gravell

    #2
    Re: Why Does Console.WriteLi ne() Not Write to Command Window?

    Quite simply, windows apps don't connect to a console.

    It can either be console or winform; Not both. This is part of the PE
    header so is more Windows than .Net.

    You could perhaps have 2 exes (one winform, one console).
    Trace.WriteLine can be useful, as this will appear in the debugger by
    default, or can be redirected.

    Marc

    Comment

    • =?iso-8859-1?q?Horacio_Nu=F1ez_Hern=E1ndez?=

      #3
      Re: Why Does Console.WriteLi ne() Not Write to Command Window?

      Is just a thought but. why you dont try:

      console.WriteLi ne("...");
      Application.Run (new Form1);


      -------------
      An additional way is change the propertys in,out of the
      System.Console, they are streams so you could put text files on

      cheers,




      Comment

      • Samuel R. Neff

        #4
        Re: Why Does Console.WriteLi ne() Not Write to Command Window?


        put a breakpoint on the first line of your app and inspect
        System.Console. Out. You'll see that it's ultimately a wrapper around
        System.IO.Strea m.NullStream.

        ((System.IO.Str eamWriter)(((Sy stem.IO.TextWri ter.SyncTextWri ter)(System.Con sole.Out))._out )).BaseStream

        Use a logging framework instead of console.writeli ne (I'd suggest
        log4net).

        HTH,

        Sam

        ------------------------------------------------------------
        We're hiring! B-Line Medical is seeking .NET
        Developers for exciting positions in medical product
        development in MD/DC. Work with a variety of technologies
        in a relaxed team environment. See ads on Dice.com.



        On 3 May 2007 11:56:25 -0700, joey.powell@top scene.com wrote:
        >I have a windows form app in C# in VS2005. In the "program.cs " file, I
        >take some command line arguments and use "Console.WriteL ine("fsdfsd")
        >to give feedback to users. When I step through the program, the code
        >block is executing, but no text is written to the command line.
        >
        >What might be causing this?

        Comment

        • Michael A. Covington

          #5
          Re: Why Does Console.WriteLi ne() Not Write to Command Window?

          <joey.powell@to pscene.comwrote in message
          news:1178218585 .415524.310380@ o5g2000hsb.goog legroups.com...
          >I have a windows form app in C# in VS2005. In the "program.cs " file, I
          take some command line arguments and use "Console.WriteL ine("fsdfsd")
          to give feedback to users. When I step through the program, the code
          block is executing, but no text is written to the command line.
          >
          What might be causing this?
          You've told the compiler that you have a windowed application. If you will
          tell the compiler to compile it as a console app (which is somewhere in
          Project Properties), you'll get a console window, and the forms will all
          still work. This is a handy secret.

          Or use System.Diagnost ics.Debug.Write Line(...) to write in the debug window
          in VS2005 while the program runs.


          Comment

          • Michael A. Covington

            #6
            Re: Why Does Console.WriteLi ne() Not Write to Command Window?


            "Marc Gravell" <marc.gravell@g mail.comwrote in message
            news:1178219821 .654742.56650@c 35g2000hsg.goog legroups.com...
            Quite simply, windows apps don't connect to a console.
            >
            It can either be console or winform; Not both. This is part of the PE
            header so is more Windows than .Net.
            Little-known fact: Actually it *can* be both. Take a Windows Forms app and
            compile it as a console app, and you'll have a console window.

            You can also use Win32 calls to create a console and attach a stream to it.


            Comment

            • Chris Nahr

              #7
              Re: Why Does Console.WriteLi ne() Not Write to Command Window?

              On Fri, 4 May 2007 00:37:33 -0400, "Michael A. Covington"
              <look@ai.uga.ed u.for.addresswr ote:
              >Little-known fact: Actually it *can* be both. Take a Windows Forms app and
              >compile it as a console app, and you'll have a console window.
              Not really, it's actually a console application that pops up a window.
              The original console window stays visible all the time.
              --
              Stay ahead in World of Warcraft with expert guides, latest patch news, class tips, dungeon strategies, PvP builds, and The War Within updates—all in one place.

              Comment

              Working...