gpt4 book ai didi

c# - 设置参数后作为控制台应用程序执行

转载 作者:行者123 更新时间:2023-11-30 22:35:15 25 4
gpt4 key购买 nike

几天前,我使用 VC#2010 Express 在 C# 中开发了一个 WinForms 应用程序。创建并保存项目后,我在项目设置中将其设为控制台应用程序,因此除了启动表单外,还会弹出一个 Windows 命令行。我使用控制台输出调试信息(只需使用 Console.Write() 函数)。

现在,我的应用程序已准备好发布。我当然不希望用户看到控制台,但我想集成一种方式来向感兴趣的人展示控制台。所以,最好的方法是一个参数,我认为(比如 -console),但我不知道如何仅在设置参数时将程序作为控制台应用程序启动。我当然知道如何处理 args[] 数组,但是我不知道在有 arg 时如何显示控制台。我已经尝试通过命令行(CMD -> prog.exe)简单地启动程序,但它没有用。程序启动,但是启动程序后控制台直接显示当前路径,和往常一样。

我的意图有没有可能?

最佳答案

据我所知,没有办法让一个二进制文件同时支持控制台和非控制台行为,选择是在启动时做出的。我见过的所有解决方法都使用两个二进制文件。

有讨论here关于 Python 如何处理这个问题(我的粗体字):

The standard Python.exe that comes with Python is known as a console application (this means it has been built to interact with a Windows console, otherwise known as a DOS box or command prompt). Although you can execute your Tkinter programs using Python.exe, your program will always be associated with a Windows console. It works just fine, but has the following side effects:

  • If you execute Python.exe from Windows Explorer, a new empty console window is created; then the Tkinter windows are created.
  • If you execute a Tkinter application under Python.exe from a command prompt, the command prompt doesn't return until the Tkinter application has finished. This will be a surprise for many users, who expect that executing a GUI program returns the command prompt immediately.

To get around this problem, Python comes with a special GUI version called Pythonw.exe. This is almost identical to the standard Python.exe, except it's not a console program, so doesn't suffer the problems described previously.

关于c# - 设置参数后作为控制台应用程序执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7484007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com