我有一个进程,它应该启动另一个进程,并且正在使用QProcess::startDetached(),因为它与forked进程没有关系。现在,我正在尝试找出一种将stdout重定向到文件的方法。当我在QProcess::startDetached()中使用setStandardOutputFile()时,到文件的重定向不起作用。而setStandardOutputFile()在QProcess::start()中工作得很好。
我认为由于QProcess::startDetached()是静态方法,它可能不适用于setStandardOutputFile(),但我在QProcess文档中看到了这句话,
Only the following property setters are supported by startDetached():
setArguments()
setCreateProcessArgumentsModifier()
setStandardOutputFile()
etc.
尝试理解文档中这句话的含义。
下面是代码的要点,
void ForkProcess()
{
QProcess processObj;
processObj.setStandardOutputFile("/tmp/stdoutfile.txt");
processObj.startDetached(processWithArguments);
}
这不会将标准输出重定向到文件,而如果我使用processObj.start(processWithArguments),重定向就可以正常工作。
你对QProcess::startDetached()为什么不能工作有什么想法吗?
发布于 2019-02-17 18:57:50
尝试使用non-static `QProcess::startDetached member...
bool QProcess::startDetached(qint64 *pid = nullptr);
下面的代码似乎适合我(Suse Linux + Qt5.12.0)...
QProcess process;
process.setProgram("ls");
process.setStandardOutputFile("/tmp/stdoutfile.txt");
process.startDetached();
https://stackoverflow.com/questions/54731162
复制相似问题