PDA

View Full Version : QProcess problem to start executable



cydside
17th June 2010, 13:15
Hi to all,
it's driving me crazy, trust me. Let me show you the code:



void frmMain::dumpSqliteDatabase()
{
QString strError;
QString strPathSqlite;

QString fileName = "Dump.sql";

QProcess p;

strPathSqlite = QDir::toNativeSeparators(QCoreApplication::applica tionDirPath() + "/data/sqlite3.exe");
strPathSqlite.replace("\\","\\\\");

p.start(strPathSqlite + " Scrab.db .dump > " + fileName);

if (!p.waitForStarted() || !p.waitForFinished(-1) || (p.exitStatus() != QProcess::NormalExit))
{
switch (p.error())
{
case (QProcess::FailedToStart) :
strError = tr("The process failed to start. Either the invoked "
"program is missing, or you may have insufficient permissions to invoke the program.");
break;
case (QProcess::Crashed) :
strError = tr("The process crashed some time after starting successfully.");
break;
case (QProcess::WriteError) :
strError = tr("An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.");
break;
case (QProcess::ReadError):
strError = tr("An error occurred when attempting to read from the process. For example, the process may not be running.");
break;
default:
strError = tr("An unknown error occurred.");
}

QMessageBox msgBox;
msgBox.setWindowTitle(tr("!!!"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(strError);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
}


I've tested the same command(C:\data>sqlite3 Scrab.db .dump > Dump.sql) in the windows 7 shell and it works, but the above code doesn't create the dumped file!

Thanks in advance for yuor help.

squidge
17th June 2010, 17:54
QProcess isn't the Windows shell. It doesn't support redirection for example.

agathiyaa
17th June 2010, 18:12
Hi,

Try...


p.setStandardOutputFile(fileName);
p.start(strPathSqlite + " Scrab.db .dump ");

cydside
17th June 2010, 18:48
Hi,

Try...


p.setStandardOutputFile(fileName);
p.start(strPathSqlite + " Scrab.db .dump ");


Thanks, the way is correct!
I just added the setWorkingDirectory to complete the task as follow:



QProcess p;

p.setStandardOutputFile(fileName);
p.setWorkingDirectory(strWorkingDirectory);


It finally works!!!