You just use Expect in your PowerShell. It is working. Powershell is also a shell; you can run code written by powershell that calls bash code that calls powershell again.
Bellow is a test, it passed.
It "can work with tcl expect" { $bs = @' echo "Do you wish to install this program?" select yn in "Yes" "No"; do case $yn in Yes ) echo "install"; break;; No ) exit;; esac done '@ $bsf = New-TemporaryFile $bs | Set-Content -Path $bsf $tcls = @' #!/bin/sh # exp.tcl \ exec tclsh "$0" ${1+" $@ "} package require Expect set timeout 100000 spawn {spawn-command} expect { "Enter password: $" { exp_send "$password\r" exp_continue } "#\? $" { exp_send "1" } eof {} timeout {} } '@ $tclf = New-TemporaryFile $tcls -replace "{spawn-command}",("bash",$bsf -join " ") | Set-Content -Path $tclf "bash", $tclf -join " " | Invoke-Expression Remove-Item $bsf Remove-Item $tclf }
Let me explain the test.
- create a bash file that is waiting for input.
- create a tcl file that calls the bash created in the first step.
- call the tcl program from powershell, it works, will not wait for input.
source share