【发布时间】:2020-04-15 19:58:42
【问题描述】:
我正在尝试创建一个脚本来运行位于userprofile 文件夹内的exe,但我似乎无法使该命令正常工作。知道如何让这个工作吗?
我试过了:
$env:userprofile\es-cli\es.exe myParameter
我收到一条错误消息:
Unexpected token '\es-cli\es.exe' in expression or statement.
也试过了:
($env:userprofile)\es-cli\es.exe myParameter 遇到错误unexpected token \es-cli\es.exe
`$($env:userprofile)\es-cli\es.exe myParameter` 遇到错误the term $ is not recognized as the name of a cmdlet...
$loc = "{0}\es-cli\es.exe" -f $env:userprofile
$loc myParameter # cant do this because $loc is a string
【问题讨论】:
-
如果用引号括起来,它会打印到正确的路径吗?
-
@OwainEsau,根据您的评论,我尝试了 `&"$env:userprofile\es-cli\es.exe" 并且成功了!谢谢!
标签: powershell