简体   繁体   English

如何在调用powershell命令的批处理脚本中转义单引号

[英]how to escape single quote in batch script calling for powershell command

before you say anything, I did a search, couldn't find anything that helped me, I also tried a few things on my own, not a thing worked so far. 在您说什么之前,我进行了搜索,找不到任何对我有帮助的东西,我还尝试了一些尝试,但到目前为止还没有奏效。

I'm not sure if it's powershell or batch related to be honest... Anyway... 我不确定是说Powershell还是批次相关...无论如何...

I have the following script: 我有以下脚本:

setlocal
if "%IsCollection%"=="y" set browsetext=Please choose the location where the 
games for %GameTitle% are installed:
if not "%IsCollection%"=="y" set browsetext=Please choose the location where 
%GameTitle% is installed:

set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%browsetext%',0x00000200,0).self.path""

for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "choice=%%I"

My problem is that when the variable %GameTitle% include a single quote, like for example "Director's Cut" it prevents from the browseforfolder window from opening, resulting in an error. 我的问题是,当变量%GameTitle%包含单引号时,例如“ Director's Cut”,它会阻止从browserforfolder窗口打开,从而导致错误。

How can this be fixed? 如何解决?

Thank you. 谢谢。

Just a note: The %GameTitle% variable is read from an external .ini file if it matters. 请注意: %GameTitle%变量是从外部.ini文件中读取的,如果需要的话。

用两个单引号代替:

set GameTitle=%GameTitle:'=''%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM