我正在使用powershell来运行另一个powershell脚本,在某些时候其他脚本要求输入一些内容,我希望能够读取其他脚本的输出并基于为其提供输入。类似于你对bash的期望。相当于在PowerShell中bash“expect”
任何想法?
谢谢
我正在使用powershell来运行另一个powershell脚本,在某些时候其他脚本要求输入一些内容,我希望能够读取其他脚本的输出并基于为其提供输入。类似于你对bash的期望。相当于在PowerShell中bash“expect”
任何想法?
谢谢
我不知道任何原生能力的确切复制。这个问题有一个答案,声称能够将内容传入/传出进程,所以它可能与你想要的一样。
How to run interactive commands in another application window from powershell
祝您好运!
您只需在PowerShell中使用Expect程序。有用。 Powershell也是一个shell,你可以运行powershell编写的代码,它会调用bash代码,这会再次调用powershell。
波纹管是一个测试,它通过。
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+"[email protected]"}
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
}
让我来解释一下这个测试。
只需发布我的解决方案,以便它可以帮助某人。我在运行一些其他需要答案的脚本时遇到同样的问题。首先创建一个文件“inputFileLocation.txt”,每行按顺序排列每个问题的答案。然后以下面的语法运行脚本。它会完成这项工作。
`cmd.exe /c "script.bat < inputFileLocation.txt"`