Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I include a command line mode in my applications?

Tags:

command-line

For learning purposes i'm developing a Class generation application in c# and winforms. I think It could be fine to include a command-line mode that allow to use the application in scripts.

It's a good practice to include a command-line mode in my applications? It would be better to have two different programs, one with GUI in one for the command-line?

like image 873
Jonathan Avatar asked Jul 13 '09 00:07

Jonathan


1 Answers

Actually having a C# application be both console and GUI is problematic. Console applications (/t:exe) are launched and then the command prompt waits for them to finish. GUI applications (/t:winexe) the command shell launches them and then returns immediately. While you can create and run forms from a 'console' application, it will always have a background console displayed. On the other hand 'Forms' application don't have the stdin, stdout and stderr connected and, while they can behave as command line tools and process command arguments, they have problems when embedded in scripts (because the standard input/output is not hooked up).

If you want to expose the functionality from both GUI driven applications and scriptable/pipe-able batch processing too the best way is to compile your functionality into a class library, then built two separate applications (one GUI one console) that leverage that library.

like image 190
Remus Rusanu Avatar answered Nov 15 '22 15:11

Remus Rusanu