问题
I'm trying to have the app tablacus explorer open a folder path. This works fine with the following formatting:
$ex = 'S:\Tools\explorer\TE64.exe'
Start-Process $ex -ArgumentList '"Tabs,Close other tabs" "Open,C:\Program Files"'
But I would really like to have the path in a variable ($dir = 'C:\Program Files'
), and I can't seem to get the quotes right so it gets interpreted properly.
Thank you for your help.
回答1:
I found two solutions for this on the MS Blog:
$Args = @"
"Tabs,Close other tabs" "Open,$dir"
"@
start $ex -ArgumentList $Args
or
start $ex -ArgumentList """Tabs,Close other tabs"" ""Open,$dir"""
回答2:
I found sometimes you need another level of quotes.
In my case, I have to set variables in -Arguments /v
, so I had to use \""
to do that.
Start-Process `
-FilePath "Installer.exe" `
-Arguments "/s /qn /v""SOME_PARAM1=\""STRING_IN_PARAM\"" SOME_PARAM2=\""STRING_IN_PARAM\"""
-Wait ;
回答3:
If your parameters are constant strings then create a shortcut and call that instead.
Set the 'target' of the shortcut to:
"S:\Tools\explorer\TE64.exe" "Tabs,Close other tabs" "Open,C:\Program Files"
Name your shortcut 'TE64' and call it in powershell like this:
start-process S:\Tools\explorer\TE64.lnk
回答4:
The following syntax works fine for me, try this:
-ArgumentList "\`"$($variable)\`""
来源:https://stackoverflow.com/questions/30524456/powershell-quotes-for-start-process-argumentlist