PowerShell and interactive external programs
I am trying to write a PowerShell script that, among other things, runs two external programs, collects the output of one, and provides it to the other.
The problem is that the second program is interactive and requires:
- password
- option (1, 2 or 3)
- option (Y or N)
- external program output 1
Note also that this is on XP with PowerShell v1 and .net v2.0 (no, I can't upgrade)
Any ideas how I would go about doing this?
CC
a source to share
Try to see if parameters can be passed via stdin, for example:
$prog1out = prog1
"mypassword`r`n1`r`nY`r`n$prog1out" | prog2
If that doesn't work, another way (hacky and possibly fragile for example) is to use SendKeys, for example:
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
[windows.forms.sendkeys]::SendWait("mypassword`r`n")
Start-Sleep -sec 1 # may need to vary this
[windows.forms.sendkeys]::SendWait("1`r`n")
# rinse and repeat
Note that SendKeys works against the foreground window, which can be a problem for you if you can't make sure the PowerShell prompt stays in the foreground.
a source to share