相当于bash的“期望”在 powershell 中
我正在使用 powershell 运行另一个 powershell 脚本,在某些时候另一个脚本要求一些输入,我希望能够读取另一个脚本的输出并基于向其提供的输入。类似于您可以在 bash 上使用 Expect 执行的操作。
有什么想法吗?
谢谢
I'm using powershell to run another powershell script, at some point the other script asks for some input, I would like to be able to read the output from the other script and based on that supply input to it. Similar to what you can do with expect on bash.
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只是发布我的解决方案,以便它可以帮助别人。我在运行其他一些需要答案的脚本时遇到了同样的问题。首先创建一个文件“inputFileLocation.txt”,其中每行中按顺序包含每个问题的答案。然后按以下语法运行脚本。它会完成工作。
Just posting my solution so that it can help someone. I faced the same problem while running some other script that will ask for answers. First create a file "inputFileLocation.txt" with answers to each question in each line in sequence. Then run the script in below syntax. And it will do the work.
解决部分问题的示例
Sample to solve part of the problem
您只需在 powershell 中使用 Expect 程序即可。有用。 Powershell也是一个shell,你可以运行powershell编写的代码,它调用bash代码,bash代码再次调用powershell。
贝娄是一个测试,它通过了。
让我解释一下测试。
You just use Expect program in your powershell. It works. Powershell is a shell too, you can run code wrote by powershell, which call bash code, which call powershell again.
Bellow is a test, it passed.
Let me explain the test.
我不知道有任何本地能力可以精确复制。这个问题有一个答案,声称能够将内容传递给进程/从进程传递内容,因此它可能符合您的需求。
如何在另一个应用程序窗口中运行交互式命令powershell
祝你好运!
I am not aware of any native capability to duplicate exact. This question has an answer that claims to be able to pass content to/from a process, so it might work with what you want.
How to run interactive commands in another application window from powershell
Good Luck!
Lee Holmes 于 2014 年在 Powershell Gallery 上发表了一篇名为“Await”的“Expect for Powershell”。事实证明,模拟 Expect 比您想象的要复杂得多,其中涉及 Win32 调用。
套餐
https://www.powershellgallery.com/packages/Await/0.8
演示
https://www.youtube.com/watch?v=tKyAVm7bXcQ
Lee Holmes put out an "Expect for Powershell" in 2014 on the Powershell Gallery called Await. Turns out emulating expect is a lot more complicated than you'd imagine, involving the Win32 calls.
Package
https://www.powershellgallery.com/packages/Await/0.8
Demo
https://www.youtube.com/watch?v=tKyAVm7bXcQ