我想知道是否有更专业的人可以帮助我解决我在 -ArgumentList
中使用变量时遇到的小问题使用 Start-Process
时.
如果我在不使用 Start-Process
的情况下运行 Exe
.\DeploymentServer.UI.CommandLine.exe register --estNumber $Number --postcode $PostCode --password $Password
一切正常,命令运行并且软件已注册。
如果我尝试
Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "register --estNumber $Number --postcode $PostCode --password $Password" -Wait -NoNewWindow
或
$Arguments = "register --estNumber $Number --postcode $PostCode --password $Password"
Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList $Arguments -NoNewWindow -Wait
命令运行但无法注册,说明它无法匹配提供的详细信息。所以我假设问题在于将参数传递给 Start-Process
, 或 -ArgumentList
解释字符串中的变量。我在这里错过了一些非常简单的东西吗?可能与 $
有关在-ArgumentList
?
最佳答案
$postcode
中有一个空格,因此您需要将参数放在引号中:
Start-Process .\DeploymentServer.UI.CommandLine.exe -ArgumentList "register --estNumber $Number --postcode `"$PostCode`" --password $Password" -Wait -NoNewWindow
关于windows - 在 -ArgumentList 中启动进程变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35117204/