大佬教程收集整理的这篇文章主要介绍了使用C中的QProcess重定向gnome-terminal的输出,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
例如:如果用户没有安装二进制文件,则应该写入bin.log,找不到该命令.我已经为生成的QProcess设置了我的环境,使其与正在运行的父进程相同(以便它可以找到bash和其他任何东西),并在调用QProcess.start()方法之前设置了工作目录.我写了一个测试用例如下:
gnome-terminal --title 'Sub-Terminal' -e 'bash -c "foo [args to foo] |& tee foo.log"'
在Qt中,我执行以下操作:
QProcess *child = new QProcess(this); QString cmd = "gnome-terminal --title 'Sub-Terminal' -e 'bash -c \"foo [args to foo] |& tee foo.log\"'"; child->setProcessEnvironment(<process environment I have created before>); child->setWorkingDirectory(<current working dir>); child->start(cmd); ...
它生成终端但不向foo.log写入任何数据.我也尝试过以下方法:
QProcess *child = new QProcess(this); QString prog = "gnome-terminal" QStringList args; args << "-x" << "bash" << "foo" << "[foo's arguments]" << "|&" << "tee" << "foo.log"; // set the process env and working dir child->start(prog,args);
有没有人对如何解决这个问题有任何建议?
我已经尝试使用QProcess.setStandardErrorFile(foo.log)和QProcess.setStandardOutputFile(foo.log)重定向stdout和stderr,但似乎这将从gnome-terminal本身重定向stdout(这不是任何东西).
args << "-e" << "bash -c 'foo [args to foo] |& tee foo.log'";
这基本上执行
bash -c 'foo [args to foo] |& tee foo.log'
在终端中,它本身执行
foo [args to foo] |& tee foo.log
在bash中.
您的猜测是正确的,读取gnome-terminal进程的输出不起作用.
以上是大佬教程为你收集整理的使用C中的QProcess重定向gnome-terminal的输出全部内容,希望文章能够帮你解决使用C中的QProcess重定向gnome-terminal的输出所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。