简体   繁体   English

Visual Studio 2015“窃取”应用程序的控制台

[英]Visual Studio 2015 “stealing” the application's console

I'm developing a gcc application using Visual Studio 2015 as an IDE. 我正在使用Visual Studio 2015作为IDE开发gcc应用程序。 The debugger is gdb. 调试器是gdb。

The application creates it's own window. 应用程序创建自己的窗口。 When I compile with a DEBUG switch, I need the application to also spawn a console window. 当我使用DEBUG开关编译时,我需要应用程序也生成一个控制台窗口。 It's used for debugging and outputing printf's from multiple threads. 它用于从多个线程调试和输出printf。 Thanks to the "-mwindows" switch, this works correctly when I execute the application from outside Visual Studio. 感谢“-mwindows”开关,当我从Visual Studio外部执行应用程序时,这可以正常工作。

Unfortunately, when I run the application from within Visual Studio, it seem to steal the console window. 不幸的是,当我从Visual Studio中运行应用程序时,它似乎窃取了控制台窗口。 No console is spawned, and the printf's output are redirected to the Output Debug window. 没有生成控制台,printf的输出被重定向到Output Debug窗口。

This wouldn't be much of a problem if the VS console actually printed the "\\n" correctly instead of stripping them out of the ouput. 如果VS控制台实际上正确地打印了“\\ n”而不是将它们从输出中剥离出来,那么这将不是什么大问题。 Everything gets printed on the same line, and the output becomes unreadable. 一切都打印在同一行,输出变得不可读。 Try as I may, I couldn't get VS to insert a newline in the Output Debug window. 尽我所能,我无法让VS在输出调试窗口中插入换行符。 I searched online a lot, and this problem seems to be well documented, but I couldn't find a satisfying answer. 我在网上搜索了很多,这个问题似乎有很好的记录,但我找不到令人满意的答案。

At this point, either of these solutions would work for me : 在这一点上,这些解决方案中的任何一个都适合我:

  1. Prevent Visual Studio from stealing the application's console window; 防止Visual Studio窃取应用程序的控制台窗口;
  2. Add special characters to all my printf in order to make the Output Debug print line feeds and carriage returns. 为我的所有printf添加特殊字符,以便使Output Debug打印换行和回车。

EDIT : Ideally, the solution should be cross-plateform, in a sense that it should not add dependency to WinAPI. 编辑:理想情况下,解决方案应该是跨平台的,从某种意义上说它不应该添加依赖于WinAPI。

EDIT2 : "\\t" seems to work as intended. 编辑2: “\\ t”似乎按预期工作。 Why does "\\n" doesn't work? 为什么“\\ n”不起作用? I also tried "\\r\\n" to no avail. 我也试过“\\ r \\ n”无济于事。

I was contacted by a Senior PM Manager for Visual Studio at Microsoft regarding this issue. 有关此问题,Microsoft的Visual Studio高级PM经理联系了我。 I posted it as a "feedback" inside Visual Studio, about four months ago (around the time I posted it here).. 我在Visual Studio中将它作为“反馈”发布,大约四个月前(我在这里发布的时间)...

He acknowledged the problem, and said they're gonna try to add support for external consoles with Update 3. 他承认了这个问题,并表示他们将尝试使用Update 3添加对外部控制台的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM