Łuk*_*Lew 5 python bash stdin stdout wrapper
我有一个运行stdin和stdout的交互式程序.我需要创建将X发送到它的stdin的包装器,检查它是否打印Y然后将包装器的stdin和stdout重定向到程序的stdin和stdout,就像程序将直接执行一样.
怎么实现这个?X和Y可以硬编码.击?蟒蛇?
编辑:我无法运行程序两次.它必须是一个例子.这是伪代码:
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2591 次 |
| 最近记录: |