我有一个交互式程序,可以运行stdin和stdout。我需要创建一个包装器,将X发送到其stdin,检查它是否打印了Y,然后将包装器的stdin和stdout重定向到程序的stdin和stdout,就像直接执行程序一样。
如何实现这个?X和Y可以硬编码。Bash?Python?
编辑:我不能两次运行程序。它必须是一个实例。以下是伪代码:
如何实现这个?X和Y可以硬编码。Bash?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()