在 PowerShell 中使用 --% [英] Using --% in PowerShell
问题描述
我已经看到 --%
与执行具有多个参数的命令相关的引用.我在谷歌上搜索有关它的更多信息时遇到了麻烦.我怀疑 Google 认为我在尝试一种特殊的语法.我希望能够从 PowerShell 执行 plink 命令并使用变量来添加这样的参数:
I've seen --%
referenced in relation to executing a command with multiple parameters. I'm having trouble googling for more information about it. I suspect Google thinks I'm trying a special syntax. I'm hoping to be able to execute the plink command from PowerShell and using variables to add the parameters like this:
&"./plink.exe" --% $Hostname -l $Username -pw $Password $Command
如果我指定了信息,它会起作用,但不能用变量替换.
It works if I specify the information, but not with variable substitution.
推荐答案
我遇到了同样的问题,有一个解决方法可以解决这个问题.我最近写了一篇关于这个的博客(使用 PowerShell 变量之后在 PowerShell v3.0 - 2013-09-17 中转义解析)从我自己的答案中获得灵感,从 PowerShell 执行外部命令不接受参数.
I had this same problem, and there is a workaround for this problem. I recently blogged about this (Use PowerShell variables after escaping parsing in PowerShell v3.0 - 2013-09-17) after taking inspiration from my own answer, Executing external command from PowerShell is not accepting a parameter.
诀窍是使用 --%
本身作为一个变量,并将它与其他变量一起包含在 PowerShell 中.
The trick is to use --%
itself as a variable and include that along with other variables in PowerShell.
所以不是这个,
&"./plink.exe" --% $Hostname -l $Username -pw $Password $Command
试试这个:
$escapeparser = '--%'
& "./plink.exe" $escapeparser $Hostname -l $Username -pw $Password $Command
可能是相关的,但我在所有变量中都使用了单引号.
It may be related, but I used single quotes in all variables.
这篇关于在 PowerShell 中使用 --%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!