PDA

View Full Version : Help with QProcess and crontab



QAZ
15th May 2011, 10:43
So i'm trying to add content to crontab. So far I've only been able to do it with QProcess("crontab <filename>") but using a temp file is not really optimal for what i'm looking for.

It's possible to do the same thing in terminal with "echo "* * * * * /command" |crontab -" but so far i haven't been able to do that with qt.

I'm using Qt 4.7 and the platform for which i'm developing is MeeGo.

Also, if anyone has any better suggestions for executing tasks that need to be repeated every x minutes/hours/days without the program hogging resources would be appreciated.

QAZ
16th May 2011, 08:50
Incase anyone else needs it, here's the solution.


QProcess cronProcess;
QString jobList = "* * * * * /command\n"; // Don't forget \n.
cronProcess.start("crontab", QStringList() << "-");

cronProcess.waitForStarted();

cronProcess.write(QByteArray(jobList.toAscii()));
cronProcess.closeWriteChannel();

cronProcess.waitForFinished();