How to escape quotes using Powershell to Command line

Discussion related to "Everything" 1.5 Alpha.
Post Reply
chippy33
Posts: 1
Joined: Sat Mar 11, 2023 8:30 pm

How to escape quotes using Powershell to Command line

Post by chippy33 »

For a custom Everything search context menu I have been using powershell to send command line search syntax to everything64.exe (1.5a ).
To search inside file content the search syntax is:
content:<text>
The issue is that when the input text has spaces it needs escaped quotation marks when passed to Everything as quotes are stripped and spaces are treated as a new funcion.

From the command line

Code: Select all

Everything64.exe "C:\Scripts" -s content:"hello world"
is shown in the search bar of Everything as:

Code: Select all

C:\Scripts  content:hello world
You can use

Code: Select all

""" to escape a literal "

Code: Select all

Everything64.exe "C:\Scripts" -s content:""""hello world""""
correctly returns

Code: Select all

C:\Scripts  content:"hello world"
To execute the command in powershell I have tried many variations for escaping the quotes around $searchTerm but I either get an error in powershell or it is not passed correctly to Everything.

Code: Select all

Invoke-Expression "& `"$pathToEverything.exe`" `"$searchPath`" -s content:`"$searchTerm`""
Am I missing something really obvious here?
void
Developer
Posts: 16672
Joined: Fri Oct 16, 2009 11:31 pm

Re: How to escape quotes using Powershell to Command line

Post by void »

Please use #quot: to escape a literal quote from powershell.
#quot: is expanded by Everything to a literal quote when reading the command line.

Please try the following powershell call:

Code: Select all

Invoke-Expression "& `"$pathToEverything.exe`" `"$searchPath`" -s content:`"#quot:$searchTerm#quot:`""
#quot:
Powershell and sending a quoted path to everything search bar
Post Reply