当前我正在使用Boost沙盒中的Boost.Process,并且遇到问题才能正确捕获我的标准输出;想知道是否有人可以给我第二双眼球成为我可能做错的事。无法使用Boost.Process捕获进程的标准输出
我试图用DCRAW(最新版本)拍摄RAW相机图像的缩略图,并捕获它们以转换为QT QImage。
过程发射功能:
namespace bf = ::boost::filesystem;
namespace bp = ::boost::process;
QImage DCRawInterface::convertRawImage(string path) {
// commandline: dcraw -e -c <srcfile> -> piped to stdout.
if (bf::exists(path)) {
std::string exec = "bin\\dcraw.exe";
std::vector<std::string> args;
args.push_back("-v");
args.push_back("-c");
args.push_back("-e");
args.push_back(path);
bp::context ctx;
ctx.stdout_behavior = bp::capture_stream();
bp::child c = bp::launch(exec, args, ctx);
bp::pistream &is = c.get_stdout();
ofstream output("C:\\temp\\testcfk.jpg");
streamcopy(is, output);
}
return (NULL);
}
inline void streamcopy(std::istream& input, std::ostream& out) {
char buffer[4096];
int i = 0;
while (!input.eof()) {
memset(buffer, 0, sizeof(buffer));
int bytes = input.readsome(buffer, sizeof buffer);
out.write(buffer, bytes);
i++;
}
}
调用转换器:
DCRawInterface DcRaw;
DcRaw.convertRawImage("test/CFK_2439.NEF");
的目标是简单的验证,我可以输入流复制到输出文件。
目前,如果我注释掉下面一行:
args.push_back("-c");
那么缩略图就被Dcraw执行写入源目录中CFK_2439.thumb.jpg的名字,这证明,我认为这个过程是用正确的参数进行调用。没有发生的事情正确地连接到输出管道。
FWIW:我在Eclipse 3.5/Latest MingW(GCC 4.4)下的Windows XP上执行此测试。
[UPDATE]
从调试,它会出现由代码到达复制视频流的时间,文件/管已经关闭 - 字节= input.readsome(...)是从未任何值而不是0.
可能不是主要问题,但'output''ofstream'应该以二进制模式打开。另外:'streamcopy'可以简化为'out << input.rdbuf();' –
input.rdbuf()的良好调用。在我写流媒体之前,我实际上正在使用它来查看引擎盖下发生了什么。 –