使用 Console2 进行 Visual Studio 调试?

发布于 2024-09-30 14:42:56 字数 105 浏览 3 评论 0原文

有没有办法使用流行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肤浅与狂妄 2024-10-07 14:42:56

有趣的问题。我研究了一下,有一些选择,但没有一个是漂亮的。

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 保持活动状态,您可以看到程序的标准输出。 (我查看了源代码,但找不到将选项卡“附加”到当前正在运行的控制台实例的方法,因此使用参数启动将始终创建一个新实例,不确定这就是您正在寻找的吗?

您可以轻松地修改项目的调试属性以反映上述内容:

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

从 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 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)"

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.

别闹i 2024-10-07 14:42:56

Scott Hanselman 对此发表了博客

他建议将此值用于控制台设置>选项卡>主要> Shell

%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86

对我来说不幸的是,这似乎不适用于 Visual Studio Express 2010,因为它缺少 vcvarsall.bat 文件。

Scott Hanselman blogged about this.

He suggests using this value for Console Settings > tabs > Main > Shell :

%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86

Sadly for me, This does not appear to work for Visual Studio Express 2010, which lacks a vcvarsall.bat file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文