Using AttachConsole, user must hit enter to get regular command line(使用 AttachConsole,用户必须按 Enter 才能获得常规命令行)
问题描述
我有一个程序,既可以作为 winform 运行,也可以从命令行运行.如果它是从命令行调用的,我会调用 AttachConsole(-1) 来附加到父控制台.
I have a progaram that can be ran both as a winform, or from command line. If it is invoked from a command line I call AttachConsole(-1) to attach to parent console.
但是,在我的程序结束后,用户必须按回车键才能返回标准命令提示符(c:>").有没有办法避免这种需要?
However, after my program ends, the user must hit enter to get back the standard command prompt ("c:>"). is there a way to avoid that need?
谢谢.我可以将它包装在一个 cmd 文件中以避免该问题,但我想从我的 exe 中完成.
Thanks. I could wrap it in a cmd file to avoid that issue, but I would like to do it from my exe.
推荐答案
尝试在你的 exe 退出前添加这一行...
Try adding this line just before your exe exits...
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
有点小技巧,但是当我遇到这个问题时,我能找到最好的方法.
Bit of a hack, but best I could find when I encountered that problem.
这篇关于使用 AttachConsole,用户必须按 Enter 才能获得常规命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 AttachConsole,用户必须按 Enter 才能获得常规命令行
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
