I have very strange problem with QProcess and it’s strange behaviour.
What i wanna get at the end is something like this (this is cmd.exe in windows 7)
C:\path_to_somewhere>cmd /c "C:\Program Files\path_to_dir\executable"
(cmd is for compatibility with show of QProcess)
So to do something like that i create this:
QProcess proc;
QString command;
QStringList attributes;
command = "c:\\windows\\system32\\cmd.exe";
QStringList << QString("/c \"C:\\Program Files\\path_to-dir\\executable"");
proc.start(command, attributes);
What i get on error output is:
Name '\"c:\Program Files\Quantum GIS Wroclaw\bin\gdalwarp.exe\"' is not recognized as
internat or external command, executable or batch file.
(it’s translated by me from polish so it may be a little diffrent in english).
Seems like the \ character is not escaped in the string, leaving the \” as to characters in command. What am I doing wrong?
I’ve tried the
proces.start(QString)
function with triple \”\”\” and it doesnt work either. I suppose the solution of this problem has to be sooo easy that I dont event think about it.
As you already noted, Qt wraps arguments containing spaces with quotes, which means that the actual command issued by
QProcesswill look something like that (not sure about the inner quotes):which is not what you want: the entire string is passed to
cmdincluding/c. Since/cand the path are two arguments, you should pass them separately toQProcess, without worrying about spaces as they will be handled automatically: