[Interest] Executing PowerShell command with quotes using QProcess

Damian Ivanov damianatorrpm at gmail.com
Thu Apr 3 08:58:37 CEST 2014


I'm sorry if this may not help but I wanted to share as it's somewhat
related. On Windows systems one can from QProccess access any Windows
cmd command.
The process should be defined as "cmd /c $mycommand" /k maybe also useful.

2014-04-03 2:34 GMT+02:00 Sze Howe Koh <szehowe.koh at gmail.com>:
> On 3 April 2014 06:23, Thiago Macieira <thiago.macieira at intel.com> wrote:
>> Em qua 02 abr 2014, às 12:18:59, Jason Kretzer escreveu:
>>>     powershellHDD.start("PowerShell -Command \"&{(Get-WmiObject
>>> Win32_LogicalDisk -Filter \\\"DeviceID='C:'\\\").Size}\"");
>>
>>> This does not work as I expect it to.  The dataHDDsize is an empty string
>>> "".  If I pull the command out and run it directly from a command prompt
>>> (removing the escaping backslashes) it runs exactly as I expect it to
>>> returning a number.   I thought maybe the number is the problem and I have
>>> similar commands that return proper letters and the same thing occurs.
>>>
>>> Style and suggestions for third party libs aside, does any one have any
>>> pointers?
>>
>> There's a comment in qprocess.cpp that reads:
>>
>>     // handle quoting. tokens can be surrounded by double quotes
>>     // "hello world". three consecutive double quotes represent
>>     // the quote character itself.
>>
>> I don't know whose idea it was to use three quotes successively to indicate a
>> quote character. It doesn't work on a regular Unix shell:
>>
>> $ echo """hello"""
>> hello
>>
>> Nor on Windows's prompt:
>> C:\>echo """hello"""
>> """hello"""
>>
>> That commit has been there since the Qt public history started. It's even
>> documented as such (I had to look it up, I didn't know):
>>         http://qt-project.org/doc/qt-5/qprocess.html#start-3
>>
>> But I don't know why it was done like that. It's highly surprising. If it
>> weren't documented, I'd be tempted to just change behaviour and go for
>> standard backslashing.
>
> That's highly unintuitive. The fact that it's Windows-only suggests
> that it was put in to work around some issue (which may not be present
> in modern versions of Windows). Candidate for change in Qt 6?
>
>
> Regards,
> Sze-Howe
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list