使用 Console2 进行 Visual Studio 调试?
有没有办法使用流行的 Console2 cmd.exe 替代品进行 Visual Studio 调试?换句话说,当我在VS下调试控制台应用程序时,我希望它使用Console2而不是cmd.exe。
Is there a way to use the popular Console2 cmd.exe replacement for Visual Studio debugging? In other words, when I debug a console app under VS, I want it to use Console2 instead of cmd.exe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的问题。我研究了一下,有一些选择,但没有一个是漂亮的。
Console.exe 接受参数,因此可以使用特定选项卡启动它并执行任意进程。然而,这个进程将始终在它自己的 cmd.exe 中运行;例如,如果您的程序是 c:\my.exe 并且您启动 Console 作为
console.exe -t tabname -rc:\myexe
Console2 内部调用CreateProcess( ... cmd.exe c :\my.exe ... )
,结果你甚至看不到 my.exe 的输出。不过,这很容易解决:将其启动为console.exe -t tabname -r "/kc:\myexe"
:/k 开关使 cmd.exe 保持活动状态,您可以看到程序的标准输出。 (我查看了源代码,但找不到将选项卡“附加”到当前正在运行的控制台实例的方法,因此使用参数启动将始终创建一个新实例,不确定这就是您正在寻找的吗?您可以轻松地修改项目的调试属性以反映上述内容:
从 VS 中启动 exe 时,它将在控制台会话中启动 exe,但是调试将不起作用,因为 VS 将尝试调试 console.exe,而不是 my.exe。现在这是一个不同的过程。将
DebugBreak();
作为 exe 的 main() 的第一行将解决这个问题,因为它会为您提供调试 exe 的选项。 ,这可能有点麻烦来实现你想要的,但我不认为还有另一种方法:控制台总是生成一个新进程,因此对其进行调试的唯一方法是在之后将调试器附加到它过程开始。Interesting question. I looked into it, there are some options but none are pretty.
Console.exe takes arguments, so it's possible to start it with a specific tab and execute an arbitrary process. However, this process will always be run within it's own cmd.exe; for example if your program is c:\my.exe and you launch Console as
console.exe -t tabname -r c:\myexe
Console2 internally callsCreateProcess( ... cmd.exe c:\my.exe ... )
, as a result you can't even see the output of my.exe. This is easily solved though: launch it asconsole.exe -t tabname -r "/k c:\myexe"
: the /k switch makes the cmd.exe stay active and you can see your program's standard output. (I looked through the source but couldn't find a way to 'attach' a tab to a currently running Console instance, so launching with arguments will always create a new instance, not sure this is what you are looking for?You can easily modify the project's debugging properties to reflect the above:
When starting your exe from within VS, it will launch your exe witin a Console session. However the debugging won't work as VS will try to debug console.exe, not my.exe since that is now a different process. Putting a
DebugBreak();
as first line in your exe's main() will sort of solve this, as it will present you the option to debug your exe. All in all, this may a bit too much of a hassle to achieve what you want, but i don't think there's another way: Console always spawns a new process, so the only way to get it debugged is to attach the debugger to it after that process started.Scott Hanselman 对此发表了博客。
他建议将此值用于控制台设置>选项卡>主要> Shell:
对我来说不幸的是,这似乎不适用于 Visual Studio Express 2010,因为它缺少 vcvarsall.bat 文件。
Scott Hanselman blogged about this.
He suggests using this value for Console Settings > tabs > Main > Shell :
Sadly for me, This does not appear to work for Visual Studio Express 2010, which lacks a vcvarsall.bat file.