mark
mark

Reputation: 62746

A simple PowerShell script that botches the PS console

This question is related in spirit to Powershell command prompt prints ^C when pressing Ctrl+C, why? - both deal with the PowerShell console being screwed up.

Given:

Consider the following script:

$iisexpress = "C:\Program Files (x86)\IIS Express\iisexpress.exe"
$config = "c:\xyz\.vs\config\applicationhost.config"
$logFile = "$env:temp\1.log"
$id = (Start-Process $iisexpress "/site:Site1","/config:$config" -PassThru -RedirectStandardOutput $logFile -NoNewWindow).Id
$id

I do not think having a solution specific configuration matters here. What matters is that I am starting a site while redirecting the output and collecting the process Id.

That's it. Try working with the console a bit. If nothing happens - run the script again, even though it should not be necessary. The console is botched.

Why? How do I fix it?

Upvotes: 3

Views: 217

Answers (1)

ravibhagw
ravibhagw

Reputation: 1740

I believe it's the -NoNewWindow flag that is causing you trouble. iisexpress.exe runs from within the Powershell window with this switch, and seems to partially hijack your input.

I'm still curious to investigate why this happens and have no answer as of yet, but an easy fix is to replace -NoNewWindow with -WindowStyle hidden

Upvotes: 6

Related Questions