2

i have changed my Main:

[STAThread]
static void Main(string[] args)
{
    if (args.Length == 0)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new fForm());
    }
    else
    {
        Console.WriteLine("Yay! I have just created a commandline tool.");
    }
}

But how can i print this massage Console.WriteLine(...) ? currently nothing happen when send argument into my exe file

user3328870
  • 341
  • 2
  • 7
  • 23

3 Answers3

4

If you're okay with the console always being visible, you can change your project's Output Type (in project properties) to "Console Application."

adv12
  • 8,443
  • 2
  • 24
  • 48
  • i don't want to see the console while using form, maybe the best option is to add another console application project into my solution ? – user3328870 May 01 '14 at 13:36
  • That's a possibility. You could try to keep all the business logic in a project that both UI's reference... – adv12 May 01 '14 at 13:57
1

Duplicate question answer here: https://stackoverflow.com/a/15079092/666899

Essentially, what you have to do is manually create the console window via Win32 (pinvoke).

edit: To further clarify, you cannot have a console if your app is set to Windows Application, and you cannot rid of the Console if your app is a console application and you only want UI. Either way you have to call the native Win32 functions to either hide the console, or create it depending on the situation.

Community
  • 1
  • 1
Dan
  • 734
  • 1
  • 9
  • 23
0

If you check the Output window in Visual Studio you'll probably find that it has the WriteLine message in it. Because there's nothing after it the application exits at that point which may appear as if nothing has happened

rh072005
  • 720
  • 6
  • 15