【发布时间】:2019-02-17 07:42:53
【问题描述】:
我有一个进程应该启动另一个进程并且正在使用 QProcess::startDetached() 因为与分叉的进程没有关系。现在我试图找出一种将标准输出重定向到文件的方法。 当我将 setStandardOutputFile() 与 QProcess::startDetached() 一起使用时,重定向到文件不起作用。 虽然 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() 不起作用有什么想法吗?
【问题讨论】:
-
您在哪个平台上运行?你能提供一个MCVE吗?