我想用MFC应用程序写入std::cerr
或std::cout
。在python脚本中,我调用这个应用程序,并希望从stdout
或stderr
读取。
两者都不起作用。仅仅使用std::cout
不会产生任何输出。在AllocConsole()
之后,我至少能够打印到调试控制台。不幸的是,python站点上仍然没有输出。你知道吗
在MFC应用程序中,我使用以下代码初始化要写入的控制台:
void BindStdHandlesToConsole()
{
// Redirect the CRT standard input, output, and error handles to the console
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
std::wcout.clear();
std::cout.clear();
std::wcerr.clear();
std::cerr.clear();
std::wcin.clear();
std::cin.clear();
}
// initialization
BOOL foo::InitInstance()
{
// allocate a console
if (!AllocConsole())
AfxMessageBox("Failed to create the console!", MB_ICONEXCLAMATION);
else
BindStdHandlesToConsole();
在python站点上,我尝试打印输出。你知道吗
process = subprocess.Popen(args,stdout=subprocess.PIPE,shell=True)
output = process.stdout.read()
process.wait()
有没有办法让我的MFC程序真正写出来,让python脚本读取标准输出?你知道吗
将内容写入stdout管道的正确方法如下:
相关问题 更多 >
编程相关推荐