0

Background Information (based on my first question): i want to integrate in my "GUI.exe" (written in c#) a help function. Then when i want to start in my cmd -> "GUI.exe --h" the help function.

Tried a stackoverflow- post: I have try to use this solution: Adding "--help" parameter to C# console application.

static bool ShowHelpRequired(IEnumerable<string> args)
{
    return args.Select(s => s.ToLowerInvariant())
        .Intersect(new[] { "help", "/?", "--help", "-help", "-h" }).Any();
}

Current problem:

I don't know where I can integrate the help function. I don't know whether a particular setting in my Microsoft Visual Studio must configure.

In advance thank you for your Support.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
Moha86B
  • 1
  • 3
  • This has nothing to do with Visual Studio. You have to include that code (probably) in your `main( args )` method. – Fildor Aug 16 '17 at 07:34
  • thx for your answer. Now don´t Need to think about a config. – Moha86B Aug 16 '17 at 08:04
  • If GUI.exe isn't a console application, then first you'll have to call either WinAPI `AllocConsole()` or `AttachConsole(ATTACH_PARENT_PROCESS)`. If you choose to attach to the parent console, note that CMD and PowerShell don't wait for a non-console child by default when interactive, so your output may get jumbled up with the shell's output. – Eryk Sun Aug 16 '17 at 11:22

1 Answers1

5

Call ShowHelpRequired in your main method :

    static void Main(string[] args)
    {

        if(ShowHelpRequired(args))
        {
            Console.WriteLine("Show help message here");
        }
    }
Ali Ezzat Odeh
  • 2,093
  • 1
  • 17
  • 17
  • thx for your post. When i itry to call the ShowHelpRequired into my main method i get one failure (s. my next post) – Moha86B Aug 16 '17 at 08:04
  • static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new GUI_Form()); } static void Main(string[] args) { if (ShowHelpRequired(args)) { Console.WriteLine("Show help message here"); } } } – Moha86B Aug 16 '17 at 08:10
  • in your comment there are two main methods, please provide the failure message. – Ali Ezzat Odeh Aug 16 '17 at 08:14
  • thx for your fast answer. Failure Message: "Compile wih /main to specify the type that contains the entry point" – Moha86B Aug 16 '17 at 08:17
  • I think you misunderstood me, my problem has unfortunately not been resolved – Moha86B Aug 16 '17 at 08:37
  • @Moha86B you need to have *only one* `Main` method, so remove the one with no parameter (eventually insert its content inside the one with args before removing it) and run. – Rafalon Aug 16 '17 at 08:46
  • @Rafalon thx for your comment. now i get this error => error CS0103: "The Name 'ShowHelpRequired' does not exist in the current context" – Moha86B Aug 16 '17 at 08:55
  • @Moha86B of course you need to add the `ShowHelpRequired` method you showed in your question, anywhere accessible from your `main` method – Rafalon Aug 16 '17 at 08:57
  • @Rafalon thx for the Information i already forgot to add the ShowHelpRequired. Now i have no failure. Now when i start the exe file via cmd = > "GUI.exe -h" then i will not get the help- Information (in cmd-Interface) – Moha86B Aug 16 '17 at 10:58
  • Here the code (from the main): static class Program { static bool ShowHelpRequired(IEnumerable args) { return args.Select(s => s.ToLowerInvariant()) .Intersect(new[] { "help", "/?", "--help", "-help", "-h" }).Any(); } static void Main(string[] args) { if(ShowHelpRequired(args)) { Console.WriteLine("Show help message here"); } – Moha86B Aug 16 '17 at 11:03
  • @Moha86B well, now **instead of** `Console.WriteLine("Show help message here");` you should write whatever you want the program to do specifically when you run it with "*GUI.exe -h*" – Rafalon Aug 16 '17 at 12:13
  • @Rafalon thx for your message It would be very helpful if you could give me a easy example to get a output in my cmd ("with GUI.exe -h"). – Moha86B Aug 16 '17 at 12:55
  • @Moha86B I'm sorry for the late answer to your comment, but I thought my latest comment was already an easy example – Rafalon Aug 28 '17 at 06:52