Qt - Wait for Qprocess to finish

Mohammad Reza  Ramezani picture Mohammad Reza Ramezani · Jul 31, 2014 · Viewed 13.3k times · Source

I'm using CMD by QProcess but I have a problem.

My code:

QProcess process;
process.start("cmd.exe");
process.write ("del f:\\b.txt\n\r");
process.waitForFinished();
process.close();

When I don't pass an argument for waitForFinished() it waits for 30 secs. I want to terminate QProcess after CMD command is executed! Not much and not less!

Answer

ahmed picture ahmed · Jul 31, 2014

You need to terminate the cmd.exe by sending exit command, otherwise it will wait for commands Here is my suggestion:

QProcess process;
process.start("cmd.exe");
process.write ("del f:\\b.txt\n\r");
process.write ("exit\n\r");
process.waitForFinished();
process.close();