我正在尝试使用boost process(0.5)库。
在asych_io.cpp
示例中,读取处理程序甚至不会被调用一次。
甚至在调用io_service.run()
之后
我正在使用Linux。
#include <boost/process.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <string>
using namespace boost::process;
using namespace boost::process::initializers;
using namespace boost::iostreams;
boost::process::pipe create_async_pipe()
{
return create_pipe();
}
int main()
{
boost::process::pipe p = create_async_pipe();
file_descriptor_sink sink(p.sink, close_handle);
child c = execute(
run_exe(search_path("nasm")),
set_cmd_line("nasm -v"),
bind_stdout(sink)
);
file_descriptor_source source(p.source, close_handle);
typedef boost::asio::posix::stream_descriptor pipe_end;
boost::asio::io_service io_service;
pipe_end pend(io_service,p.source);
boost::array<char, 4096> buffer;
boost::asio::async_read(pend, boost::asio::buffer(buffer),
[&](const boost::system::error_code&, std::size_t bytes_transferred){
std::cout << std::string(buffer.data(), bytes_transferred) << std::flush;
});
io_service.run();
}
答案 0 :(得分:0)
我替换后
boost::asio::async_read(pend...
与
pend.async_read_some(...
它对我有用。