Should I include a command line mode in my applica

2019-06-21 04:05发布

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?

10条回答
神经病院院长
2楼-- · 2019-06-21 04:22

Yes. If you think the program will be useful in a scripted environment then include a command line mode (without UI) so it can be used in scripts.

It doesn't have to be a separate application, but it can be. Whether you want to do that or not is entirely up to you. I'd imagine that if you had two applications they'd share the same logic assemblies but the interface (one a GUI the other a command line) would just be different.

查看更多
走好不送
3楼-- · 2019-06-21 04:23

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.

查看更多
smile是对你的礼貌
4楼-- · 2019-06-21 04:24

Another great idea is to embed a scripting language. Then your program can be controlled by a script, and you get all the logic, branching, etc from the scripting language "for free."

There are many choices of what you can embed. Lua is one of the most popular and intended for just that purpose and is an excellent choice.

However, for a general purpose app, I'd take a hard look at embedding Python. Python is so popular, you'd have a larger group of people willing to take the effort to write a script for your app.

查看更多
欢心
5楼-- · 2019-06-21 04:27

I agree with michaelsafyan about creating a library with core functionality.

What I would add is that you should check out powershell cmdlets as well.

Much command line activity will be migrating to powershell and it brings a lot to the table.

http://en.wikipedia.org/wiki/Windows_PowerShell

查看更多
登录 后发表回答