首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Poco,子通信挂起(python解释器是子)

Poco,子通信挂起(python解释器是子)
EN

Stack Overflow用户
提问于 2016-12-29 03:10:24
回答 1查看 131关注 0票数 1

我希望与python & lua脚本进行通信,但是python不像预期的那样工作。Python挂起:

日志:

代码语言:javascript
复制
lua << 'hello!',   lua >> 'hello!'
lua << 'hello!',   lua >> 'hello!'
lua << 'hello!',   lua >> 'hello!'
python << 'hello!',   

主要C++应用程序:

代码语言:javascript
复制
#include <iostream>
#include "Poco/Process.h"
#include "Poco/PipeStream.h"
void test( char const* interpreter, char const* filename )
{
   std::vector<std::string> args { filename };
   Poco::Pipe outPipe;
   Poco::Pipe inPipe;
   Poco::ProcessHandle process_handle = Poco::Process::launch( interpreter, args, &inPipe, &outPipe , nullptr/*errPipe*/ );
   Poco::PipeInputStream output_reader(outPipe);
   Poco::PipeOutputStream input_writer(inPipe);
   for(int repeat_counter=0; repeat_counter<3; ++repeat_counter)
   {
      auto send_str("hello!");
      input_writer << send_str << std::endl;
      std::cout << interpreter << " << '" << send_str << "',   " );
      std::cout.flush();
      std::string receiv_str;
      output_reader >> receiv_str;
      std::cout << interpreter << " >> '" << receiv_str << "'" << std::endl;
   }
}
int main()
{
   test("lua","test.lua");
   test("python","test.py");
   return 0;
}

Lua脚本:

代码语言:javascript
复制
for i=1,10 do
   print(io.read())
end

Python脚本:

代码语言:javascript
复制
for i in range(0,10):
   print(raw_input())

终端中的两个脚本的工作原理相同.

解决方案:因为Python必须只使用sys.stdout.write &刷新,谢谢@宏狼

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-29 03:31:32

我猜python的print函数并不是直接输出到stdout,或者幕后发生了一些有趣的事情。试着用sys.stdout.write代替它。别忘了先去import sys

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41372633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档