我有一个程序,既可以作为 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 才能获得常规命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!