作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我一直在绞尽脑汁试图找出 Powershell 忽略命令行参数的原因,我想我终于发现字符串参数上的尾部反斜杠以某种方式混淆了参数解析。
我有
param (
[Parameter(Mandatory=$true)][String]$p1,
[Parameter(Mandatory=$true)][String]$p2
)
Write-Output "p1:$p1, p2:$p2"
最终,我需要从 Windows 任务调度程序调用类似这样的东西,这意味着使用 powershell.exe
作为程序并将此脚本和参数添加为 args。
在生产中,p1 是一个文件路径。所以我尝试:
PS C:\source> C:\Windows\System32\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Bypass -File .\myScript.ps1 -p1 'C:\Program Files\' -p2 asdf
cmdlet myScript.ps1 at command pipeline position 1
Supply values for the following parameters:
p2:
为什么提示?参数就在那里。我最终无意中删除了 p1 的结尾反斜杠:
PS C:\source> C:\Windows\System32\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Bypass -File .\myScript.ps1 -p1 'C:\Program Files' -p2 asdf
p1:C:\Program Files, p2:asdf
这是一个错误吗?
我是一名优秀的程序员,十分优秀!