我应该在我的应用程序中包括命令行模式吗? [英] Should I include a command line mode in my applications?

查看:87
本文介绍了我应该在我的应用程序中包括命令行模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了学习目的,我在c#和winforms中开发了一个类生成应用程序。我认为可以包括允许在脚本中使用应用程序的命令行模式。

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?

推荐答案

实际上有一个C#应用程序既是控制台又是GUI有问题。控制台应用程序( / t:exe ),然后命令提示符等待它们完成。 GUI应用程序( / t:winexe )命令shell启动它们,然后立即返回。虽然可以从控制台应用程序创建和运行表单,但它始终会显示一个后台控制台。另一方面,Forms应用程序没有连接stdin,stdout和stderr,虽然它们可以作为命令行工具和进程命令参数,但是当嵌入到脚本中时会出现问题(因为标准输入/输出不是挂接)。

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).

如果你想从GUI驱动的应用程序和脚本/管道能批量处理公开功能,最好的方法是将你的功能编译成类库,然后构建了利用该库的两个单独的应用程序(一个GUI一个控制台)。

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.

这篇关于我应该在我的应用程序中包括命令行模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆