例如:如果用户没有安装二进制文件,则应该写入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 dirchild->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的输出所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)