我正在尝试调用 System.Diagnostics.Process 的 Start 方法。我在互联网上看到了许多其他例子,但是当我运行我的代码时:
$process = new-object System.Diagnostics.Process
$config.variables.properties | foreach {
$process.StartInfo.EnvironmentVariables.Set_Item($_.name, $_.value)
}
$process.StartInfo.UseShellExecute = false;
$process.StartInfo.FileName = "C:\Program Files\IIS Express\iisexpress.exe"
$process.StartInfo.Arguments = "/config:$configPath\${name}ApplicationHost.config \site:$name"
$process.Start()
我得到这个毫无意义的错误:
Exception calling "Start" with "0" argument(s): "The parameter is incorrect"
At C:\Users\critc\Source\run-iisexpress.ps1:67 char:1
+ $started = $process.Start() | Out-Null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : Win32Exception
此方法具有 0 参数重载。事实上,如果我从调用 powershell 中删除括号,它的无限智慧会告诉我零参数重载
OverloadDefinitions
-------------------
bool Start()
Powershell在拖钓我!最初我正在创建一个 ProcessStartInfo 实例并尝试将其传递给静态 Process.Start 方法,我得到了同样的错误(除了它说with "1" argument(s)
)
更新
这是我更新的有效代码。
$process = new-object System.Diagnostics.Process
Get-Member -inputObject $config.variables -memberType Properties | foreach {
$value = $config.variables | select -exp $_.name
$process.StartInfo.EnvironmentVariables.Set_Item($_.name, $value)
}
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.FileName = "C:\Program Files\IIS Express\iisexpress.exe"
$process.StartInfo.Arguments = "/config:`"$configPath\${name}ApplicationHost.config`" /site:$name"
$started = $process.Start()
if ($started) {
$process.WaitForExit()
}