0
我想用我的MFC应用程序写入std::cerr
或std::cout
。在一个python脚本中,我称这个应用程序,我想从stdout
或stderr
读取。 两者都不起作用。仅使用std::cout
就不会产生输出。在AllocConsole()
之后,我至少能够打印到调试控制台。不幸的是,python网站上仍然没有输出。使用MFC写入stdout并通过python读取stdout Popen
在我的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();
蟒网站,我尝试打印输出。
process = subprocess.Popen(args,stdout=subprocess.PIPE,shell=True)
output = process.stdout.read()
process.wait()
有没有办法让我的MFC程序真正写入,并且Python脚本读取标准输出?
尝试设置'标准错误= subprocess.PIPE'以及然后使用'(输出,错误)= process.communicate()'没有'read()'和'.wait()'。 – cdarke
仍然没有输出:( – dgrat
你测试输出和错误吗? – cdarke