views:

143

answers:

2

I have a command-line utility that gets quite a bit of downloads from my site. I'm trying to show the usage when a user uses the /? or /help parameters. I have a function called ShowUsage() that has nicely formatted text on the parameters available.

I see that ShowUsage() gets called fine from Visual Studio 2008, when I'm using the command-line parameters in the project properties. However the exe does not display the help text when run from the command-line. Here's a shortened version of ShowUsage():

private static void ShowUsage()
{
    Console.WriteLine(Environment.NewLine);
    Console.WriteLine("Text File Splitter v1.4.1  released: December 14, 2008");
    Console.WriteLine("Copyright (C) 2007-2008 Hector Sosa, Jr");
    Console.WriteLine("http://www.systemwidgets.com");
    Console.WriteLine("");
}

I tried a bunch of different things from my searches in Google, but none are working. I know this has to be something simple/easy, but for the life of me, I can't figure this one out.

EDIT:

The code that calls ShowUsage():

if (!Equals(cmdargs["help"], null) || !Equals(cmdargs["?"], null))
{
    ShowUsage();
}

I have a class that parses the parameters into the cmdargs array. I confirmed that the parameters are in the array. It's something inside ShowUsage() that is preventing from showing the text.

I'm going to try the debug trick, and see what I find.

I'm not using Console.Out anywhere.

d03boy - Just personal preference. It makes the text less cluttered onscreen, at least to me.

EDIT #2

Ok, some more information... I'm running VS2008 in Vista Ultimate 64 bit. I just check the project properties and it is set to "Windows Application." This utility is 32 bit.

I'm going to experiment with creating a separate project in the solution that is a true console program, as some of you have advised.

A: 

Are you redirecting Console.Out to somewhere else?

Try throwing a System.Diagnostics.Debugger.Launch() in the ShowUsage method so you can see if it's getting hit at runtime.

Can you reproduce the issue with a simple exe, only accepting those help parameters?

JD Conley
"Can you reproduce the issue with a simple exe, only accepting those help parameters?" Yes, that's how I found out that it was not showing the help text.
hectorsosajr
Alright, I tried the System.Diagnostics.Debugger.Launch() trick, and it gets called from within ShowUsage() and I can step through with the debugger. Still no dice. The text shows in the Output window, but not when I run the exe from the command line. *boggle*
hectorsosajr
+2  A: 

Can you define "not working"? Simply not doing anything? Throwing an exception? I would expect the problem to be in the Main(...) method - i.e. ShowUsage() isn't being called. Another common issue is not rebuilding it in the correct configuration, so bin/release (or whatever) isn't updated.

Have you built the app as a console exe? i.e. is the "Output Type" = "Console Application" in project properties? It needs to be in order to access the console...

For info, I find the easiest way to do a console help screen (once it gets beyond a handful of lines) is to embed a .txt file into the exe; then I just write out the text file (perhaps still using string.Format if I want to replace tokes).

Alternatively, there is the alternative string format:

    Console.WriteLine(@"
Text File Splitter v1.4.1  released: December 14, 2008
Copyright (C) 2007-2008 Hector Sosa, Jr
http://www.systemwidgets.com

");
Marc Gravell
"not working" = no text is shown.
hectorsosajr
And what is `cmdargs` in your edited question? That isn't part of the boiler-plate. If it is a dictionary, how are you filling it?
Marc Gravell
cmdargs gets populated from a class called Arguments, which parses the parameters for me. This part works, as I see the correct parameters inside cmdargs when I step through it with the debugger.
hectorsosajr
The issue is that the program is not an actual console application. It is a winform app that can take command-line arguments without showing the form. In order to do what I want, it needs to be a Console Application as Marc suggested. So one part of the program is a Winform app, and the other part a Console app.
hectorsosajr