使用 Qprocess 或系统调用 R 时如何获取输出
我想简单地执行 R 脚本,因为
R --file=x.R
它在命令行上运行良好。然而,当我尝试在 C++ 中进行系统调用时,
QProcess::execute("R --file=x.R");
或者
system("R --file=x.R");
程序 R 运行并退出,但我看不到程序应该生成的输出。如果程序不使用标准输出(例如 R),如何在系统调用后获取输出作为输出文件或在程序自己的控制台中?
感谢您抽出时间。
I would like to execute a R script simply as
R --file=x.R
It runs well on the command line. However when I try the system call in C++ by
QProcess::execute("R --file=x.R");
or
system("R --file=x.R");
the program R runs and quits but I can't see the output the program is supposed to generate. If a program uses no stdout (such as R), how do I fetch the output after a system call either as a output file or in the program's own console?
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QProcess
允许您捕获命令的输出跑步;但不是通过您使用的静态函数调用。相反,请尝试这样的操作:当然,为了正确执行操作,您可能需要启动进程,然后在连接到进程对象的完成信号的槽中执行其余代码。如果您愿意,您还可以从标准输出或错误中增量读取。或者,您可以设置对象来接收输出或错误作为这些对象的输入。
QProcess
allows you to capture the output of the command you run; but not through the static function call you used. Instead, try something like this:Of course, to do things properly, you might want to start the process, then do the rest of the code in a slot connected to the process object's finished signal. You can also read from the standard output or error incrementally, if you so desire. Or you can set objects to receive the output or error as input to those objects.