如何实现stdin,stdout包装器?

如何实现stdin,stdout包装器?,第1张

概述我有一个运行stdin和stdout的交互式程序.我需要创建将X发送到它的stdin的包装器,检查它是否打印Y然后将包装器的stdin和stdout重定向到程序的stdin和stdout,就像直接执行程序一样.怎么实现这个? X和Y可以硬编码.击?Python?编辑:我无法运行程序两次.它必须是一个例子.这是伪代码:def wrap(cmd, in, exp

我有一个运行stdin和stdout的交互式程序.
我需要创建将X发送到它的stdin的包装器,检查它是否打印Y然后
将包装器的stdin和stdout重定向到程序的stdin和stdout,就像直接执行程序一样.

怎么实现这个? X和Y可以硬编码.击?Python?

编辑:我无法运行程序两次.它必须是一个例子.
这是伪代码:

def wrap(cmd,in,expected_out):  p = exec(cmd)  p.writetoStdin(in)  out = p.readBytes (expected_out.size())  if (out != expected_out) return fail;  # if the above 4 lines would be absent or (in == "" and out == "")  # then this wrapper would be exactly like direct execution of cmd  connectpipe (p.stdout,stdout)  connectpipe (stdin,p.stdin)  p.continueExecution() 
最佳答案Expect用于自动运行其他程序 – 基本上你用纯文本写的东西,

启动这个程序.当它打印出“用户名”这个词时,请将其用户名发送给我.当它发送“密码”时,请将密码发送给我.

它非常适合驾驶其他程序.

总结

以上是内存溢出为你收集整理的如何实现stdin,stdout包装器?全部内容,希望文章能够帮你解决如何实现stdin,stdout包装器?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1205918.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存