0

I have the following C# code

class Test 
{
    public static void Main(String[] argv) 
    { 
        Console.WriteLine("Hello "); 
    }
}

When I run the program from the command prompt, I do not see output. The c# file name is file.cs and compiles into file.exe.

When I run this from the command prompt:

c:\>file.exe

I do not see any output. But it works if I run this:

c:\>file.exe | more

I understand I need to do something other that console.WriteLine(). Is there any way that I can redirect all Console.WriteLine() calls to standard output?

8
  • 5
    well it could be a number of issue's but can't tell without seeing your Main section of the code.. please show some relevant code also if you are wanting to pause the console to see the output use Console.Read() or Console.ReadLine() method Commented Dec 17, 2014 at 19:35
  • 2
    Post some code. And as a side note, don't call it a DOS shell or DOS window. Those haven't existed since like Windows 98. Its just called a command window now. Commented Dec 17, 2014 at 19:36
  • 2
    If you could see it with | more option than probably, you have other statements coming to console, causing it to scroll. Commented Dec 17, 2014 at 19:36
  • 7
    What is your project type? If it's a Windows Forms app, that would explain it. Commented Dec 17, 2014 at 19:40
  • 2
    Code in the post please. You can't read it in comments. Commented Dec 17, 2014 at 19:41

1 Answer 1

3

Application type was set to Windows application in Visual Studio project properties. I set the application type to "Console". This fixed the issue. Now all Console.WriteLine statements gets printed to command window.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.