Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling Qprocess with arguments containing spaces - Windows

I am trying to call an executable with qprocess and pass some arguments which might (and most probably will) contain spaces (not all of them). The executable is a python script that has been packaged with Py2exe. The python script uses optparse to parse the arguments.

If I call the py2exe.exe in cmd.exe the call is like this:

pythonExecutable.exe -aarg_a -barg_b -c"path with spaces" -darg_d

A call like this will be successful.

I want to do this through a Qt application using Qprocess, but I can't find a way to do it because Qprocess will strip any quotes("") leaving the arguments broken wherever spaces appear.

I seem to be missing something, can anyone help with this issue?

like image 576
helplessKirk Avatar asked Aug 27 '15 14:08

helplessKirk


1 Answers

that won't be much of an issue if u use the QProcess in a more proper way

QString program = "pythonExecutable.exe";
QStringList arguments;
arguments <<"-aarg_a"<< "-barg_b"<< "-c\"path with spaces\""<< "-darg_d";

QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

normaly when u have arguments with space and do't need a " symbol

you just have to pass the argument in a QStringList

QString program = "pythonExecutable.exe";
QStringList arguments;
arguments <<"a"<< "path with spaces";

QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

this program is a modified version of example program listed in the Qt docs Here

like image 156
Midhun Avatar answered Oct 19 '22 21:10

Midhun