Reputation: 1834
I'm trying to call the Start method of a System.Diagnostics.Process. I've seen many other examples on the internet doing that exact same however when I run my code:
$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()
I get this meaningless error:
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
This method has a 0 parameter overload. Infact if I drop the parentheses from the call powershell in it's infinite wisdom tells me theres a zero parameter overload
OverloadDefinitions
-------------------
bool Start()
Powershell is trolling me! Originally I was creating a ProcessStartInfo instance and trying to pass it to the static Process.Start method and I was getting the same error (except it said with "1" argument(s)
)
UPDATE
Heres my updated code that works.
$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()
}
Upvotes: 1
Views: 550
Reputation: 7153
Something tells me your parameters are incorrect, and you have a space in $configPath
. But that is just a hunch... It would be better if you supplied values of $configPath
and $name
in your question.
What happens if you use:
$process.StartInfo.Arguments = "/config:`"$configPath\${name}ApplicationHost.config`" /site:`"$name`""
Upvotes: 1