使用Console2进行Visual Studio调试吗? [英] Use Console2 for Visual Studio debugging?

查看:90
本文介绍了使用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.

推荐答案

有趣的问题.我调查了一下,有一些选择,但是没有一个很漂亮.

Interesting question. I looked into it, there are some options but none are pretty.

Console.exe具有参数,因此可以使用特定选项卡启动它并执行任意进程.但是,此过程将始终在其自己的cmd.exe中运行;例如,如果您的程序是c:\ my.exe,并且您以console.exe -t tabname -r c:\myexe身份启动Console时,Console2在内部调用了CreateProcess( ... cmd.exe c:\my.exe ... ),结果您甚至看不到my.exe的输出.不过,这很容易解决:以console.exe -t tabname -r "/k c:\myexe"身份启动:/k开关使cmd.exe保持活动状态,您可以看到程序的标准输出. (我查看了源代码,但是找不到将选项卡附加"到当前正在运行的Console实例的方法,因此使用自变量启动总是会创建一个新实例,不确定这是您要寻找的吗?

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 calls CreateProcess( ... 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 as console.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:

Command: /path/to/console.exe
Command Arguments: -t tabname -r "/k $(TargetPath)"

从VS中启动exe时,它将在控制台会话中启动exe.但是,调试将无法进行,因为VS会尝试调试console.exe,而不是my.exe,因为现在这是一个不同的过程.将DebugBreak();作为exe的main()的第一行将解决此问题,因为它将为您提供调试exe的选项.总而言之,这可能有点麻烦,无法实现您想要的目标,但是我不认为有另一种方法:控制台总是产生一个新进程,因此调试它的唯一方法是将调试器附加到在该过程开始之后.

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.

这篇关于使用Console2进行Visual Studio调试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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