PDA

View Full Version : QProcess issue in executing a exe with command line arguments



nikhilqt
11th November 2010, 13:30
Hi,

I have a issue in setting the QProcess to run executable with the arguments. The Qt code for the same is as below,



QProcess* processSQLDB = new QProcess(this);

// some path where i require the output
processSQLDB->setWorkingDirectory(sToolAccessfilepath);

QString sExeName = "\"D:/app 1/app.exe\"";

QStringList sArgs;
sArgs << "DBFile.db";
sArgs << "<";
sArgs << sDataFileName;

processSQLDB->start( sExeName , sArgs);

if (!processSQLDB->waitForStarted())
return false;

// to display stdout, stderr,this gives an empty string
qDebug() << processSQLDB->readAll();


The output of this snippet is the creation of the file "DBFile.db". But it is not happening. Am i doing any mistake?

But if i goto cmd prompt and execute the same thing like.,

c:/> "D:/app 1/app.exe" DBFile.db < sDataFileName. This works perfectly.

high_flyer
11th November 2010, 13:59
you need to use escape character for the slashes.

nikhilqt
12th November 2010, 06:52
Even after putting escape character it is not working. And the other thing what i observed is

1) The exe(exe without args)invokes only if i use startDetached(...) method but not start(...).
2) Even if the exe do not contains path and i try to execute the QProcess() plainly having all the required files in the current directory then also am not able to get the output. But if use something like this ,


QString str = "app.exe" + " DBFile.db" + " < " + sDataFileName;

system(str.toAscii());

This works!!,But the problem is, this flashes the cmd window, which is not appreciated. Any inputs would be helpful. Thanks.

high_flyer
12th November 2010, 08:34
even after putting escape character it is not working. And the other thing what i observed is
Please post the code

nish
12th November 2010, 08:37
did you use waitForFinished() before taking out the std output

nikhilqt
12th November 2010, 09:44
did you use waitForFinished() before taking out the std output

yes. I tried that too. But there won't anything directed stdout, the confirmation is creation of the DBfile.db. And also there is no any stderror data too. Let me know if anything need to do.


Please post the code

I have used the same code posted above with small changes as suggested below,

First way:
QString sExeName = "\"D:\\app 1\\app.exe\"";
Second way:
QString sExeName = "\"D:/app 1/app.exe\"";

And also as said in the above post, even i dump all the files in the current directory then also there is no output, means creation of file but whick works with the 'Sytem(...) command.

nikhilqt
15th November 2010, 06:26
Guys, Please let me know if you have any inputs?

high_flyer
15th November 2010, 09:00
try this:

QString sExeName = "D:\\app 1\\app.exe";