PDA

View Full Version : arg!!!! QProcess on win32



gfunk
23rd January 2008, 22:18
Very annoying... I'm trying to pass to QProcess::start() this argument:
INSTALLDIR="C:\Program Files\Folder"
However, there's a function call in qprocess_win.cpp called qt_create_commandline that insists on double quoting my argument as so:
"INSTALLDIR="C:\Program Files\Folder""
because it sees the space between "Program" and "Files" and thinks that extra quotes are needed. And this causes the external program that I'm start()'ing to parse the argument incorrectly. Arg!! How can I get around this? How can I pass a raw string to start() without the extra Qt argument massaging?

wysota
23rd January 2008, 22:31
What do you need the quotes for? Is "INSTALLDIR" an environment variable you are trying to set or is it a real argument for the program?

gfunk
23rd January 2008, 22:36
It's not an environment variable, I'm actually trying to set a Windows Installer property for an installer that I'm calling from my Qt program, and this installer is actually quite sensitive to these extra double quotes.

It seems that the Qt code should attempt to parse the arguments and ignore spaces that are already escaped and enclosed within double quotes, rather than just indiscriminately check if the arg contains a space anywhere in it. And I'd rather not have to try to modify Qt source and I wish there was a way around it... cursed time deadlines :crying:

wysota
24th January 2008, 00:24
It's not an environment variable, I'm actually trying to set a Windows Installer property for an installer that I'm calling from my Qt program, and this installer is actually quite sensitive to these extra double quotes.

But do you need any quotes here? Try removing your quotes, they are probably not needed at all.


It seems that the Qt code should attempt to parse the arguments and ignore spaces that are already escaped and enclosed within double quotes, rather than just indiscriminately check if the arg contains a space anywhere in it. And I'd rather not have to try to modify Qt source and I wish there was a way around it... cursed time deadlines :crying:

Actually I never heard of Qt adding any quotes to parameters. I don't know how this is on Windows, but on Unix systems they are not needed because the argument is simply pushed into the array of arguments passed to execve() later on. Are you certain those quotes are really there? I would be surprised if this behaviour was platform dependent.

Can you show us the code you have written to spawn the external process?

gfunk
24th January 2008, 01:00
But do you need any quotes here? Try removing your quotes, they are probably not needed at all.

Yes, it needs the quotes around the path, otherwise it will interpret only only up to the first space in the pathname. And the external program won't interpret my argument at all if it has quotes entirely around it. "INSTALLDIR=C:\Program Files\Folder" doesn't work.


Actually I never heard of Qt adding any quotes to parameters. I don't know how this is on Windows, but on Unix systems they are not needed because the argument is simply pushed into the array of arguments passed to execve() later on. Are you certain those quotes are really there? I would be surprised if this behaviour was platform dependent.
well, i guess that's why they had to write a qprocess_win.cpp :(


Can you show us the code you have written to spawn the external process?

For the curious, the program is essentially any Windows Installer installer exe, or if you have an msi file, you can run it through with msiexec.exe passing in the property described above, which should be on any Windows computer.



QString arg = QString("INSTALLDIR=%1%2%3").arg(QLatin1Char('"'))
.arg(mSetDest.installFolder())
.arg(QLatin1Char('"'));
QStringList args;
args << arg;
mpInstallProcess->start(cmd, args);

wysota
24th January 2008, 08:21
Yes, it needs the quotes around the path, otherwise it will interpret only only up to the first space in the pathname.
"It" being the installer? Because your application will treat it as a single argument, I'm sure of that. That's what those additional quotes are for.


And the external program won't interpret my argument at all if it has quotes entirely around it. "INSTALLDIR=C:\Program Files\Folder" doesn't work.

Try:

QString a = QString("INSTALLDIR=\\\"%1\\\").arg(path);



For the curious, the program is essentially any Windows Installer installer exe, or if you have an msi file, you can run it through with msiexec.exe passing in the property described above, which should be on any Windows computer.
Provided one is running Windows... And if the installer can't handle those quotes, it's simply dumb and should be replaced by some more intelligent application.

Bitto
26th January 2008, 08:27
Have you tried triple quoting?

http://doc.trolltech.com/4.3/qprocess.html#start-2

GTBuilder
27th January 2008, 18:40
Have you tried:

INSTALLDIR=C:\Progra~1\Folder

Windows provides some backward compatibility to older systems where filenames were restricted to 8 characters.