It is currently October 25th, 2021, 7:13 am

[(NOT A)BUG]Double Quotes and RunCommand Parameter

Report bugs with the Rainmeter application and suggest features.
User avatar
death.crafter
Posts: 1065
Joined: April 24th, 2021, 8:13 pm

Re: [BUG]Double Quotes and RunCommand Parameter

Post by death.crafter »

jsmorley wrote: September 3rd, 2021, 3:46 pm I could see this being an issue worth dealing with though, as this would be a problem:

Parameter=Write-Host 'I "need" this displayed'
Exactly!

In fact what brought this up is:

Code: Select all

[GetVolume]
Measure=Plugin
Plugin=RunCommand
Program=Powershell
Parameter=$null=Get-Volume; ((Get-Volume).GetEnumerator() | %{($_.DriveLetter)+'='+$($_.FileSystemType)}) -join '|'
OutputType=ANSI
The original parameter was:
$null=Get-Volume; ((Get-Volume).GetEnumerator() | %{"($_.DriveLetter)=$($_.FileSystemType)"}) -join '|'.

I had to count the characters to find out the error lmao.
I know I did a dumb thing. I could have just looked at the column index in vscode
from the Realm of Death
My Current Desktop
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG]Double Quotes and RunCommand Parameter

Post by jsmorley »

So it seem to me that the current rule is to use single quotes rather than double quotes as delimiters on a Parameter option to PowerShell in RunCommand, and if you need to pass a literal double quote, \" escape it.
User avatar
death.crafter
Posts: 1065
Joined: April 24th, 2021, 8:13 pm

Re: [BUG]Double Quotes and RunCommand Parameter

Post by death.crafter »

jsmorley wrote: September 3rd, 2021, 4:16 pm So it seem to me that the current rule is to use single quotes rather than double quotes as delimiters on a Parameter option to PowerShell in RunCommand, and if you need to pass a literal double quote, \" escape it.
Hmm, escaping \" seems to work.
from the Realm of Death
My Current Desktop
User avatar
Brian
Developer
Posts: 2272
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG]Double Quotes and RunCommand Parameter

Post by Brian »

Run command doesn't change any text from the Parameter or Program options. By best guess is how quotes are interpreted by Windows - or more importantly, how parameters are sent to programs.

Take this for example:

Code: Select all

Program=powershell.exe
Parameter=echo "I need this displayed"
What is sent to Windows is : powershell.exe "echo "I need this displayed""
The first parameter sent is: echo (with a trailing space)
The second parameter is: I
The third parameter is: need
etc.

This is why there is a CRLF after each word.


So the answer to this specific instance, is to use escaped quotes or single quotes (which Powershell will interpret correctly, but other programs may not).

Code: Select all

Program=powershell.exe
Parameter=""echo \"I need this displayed\"""
or this:

Code: Select all

Program=powershell.exe
Parameter=""echo 'I need this displayed'""
Note, I added double quotes "" on the Parameter options since Rainmeter will strip off leading and trailing quotes.

-Brian
User avatar
jsmorley
Developer
Posts: 22374
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG]Double Quotes and RunCommand Parameter

Post by jsmorley »

The distinction is that in the PS UI, it's all and only parsed by PS. With RunCommand, it is first parsed by Windows, then passed to PS as a command line. Windows has it's own arcane rules about double quotes on the command line. It's Windows, and not Rainmeter or RunCommand or PowerShell, that is borking the double quotes.

So the rule is to use single quotes rather than double quotes as delimiters in a Parameter option to PowerShell in RunCommand, and if you need to pass a literal double quote, \" escape it.

Parameter=Write-Host 'I \"need\" this displayed'
I "need" this displayed
User avatar
death.crafter
Posts: 1065
Joined: April 24th, 2021, 8:13 pm

Re: [BUG]Double Quotes and RunCommand Parameter

Post by death.crafter »

Brian wrote: September 3rd, 2021, 4:48 pm
Ahh makes sense.

Guess it was not a bug after all. Tho docs should cover it.
from the Realm of Death
My Current Desktop