windows - 在 -ArgumentList 中启动进程变量

标签 windows powershell

我想知道是否有更专业的人可以帮助我解决我在 -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/

相关文章:

c# - "Add-Member"到一个类型,而不仅仅是 PowerShell 中该类型的对象

windows - Git 预提交 Hook 未在 Windows 上运行

clock() 在 Windows 机器上返回负时差

powershell - 是否有任何脚本可以在整个本地网络中搜索 UPnP 设备?

xml - 在 PowerShell 中更改 XML 标签并保留内容。

Powershell Get-ChildItem 目录中的最新文件

asp.net - 从 ASP.NET 网站创建独立的 Windows 应用程序

c++ - NetBeans C++ 8.0.2 输出中这些消息的含义是什么?

.net - 将 VS MBCS 源代码表达式转换为 Unicode

Powershell Windows 2003 通配符不起作用