I have an interactive program that runs stdin and stdout. I need to create a wrapper that will send X stdin to it, make sure it prints Y, and then redirect the wrapper stdin and stdout to the stdin and stdout program just like the program will execute directly.
How to implement this? X and Y can be hardcoded. Bash? Python
Edit: I cannot run the program twice. This should be one case. Here is the pseudo code:
def wrap(cmd, in, expected_out):
p = exec(cmd)
p.writeToStdin(in)
out = p.readBytes (expected_out.size())
if (out != expected_out) return fail;
connectpipe (p.stdout, stdout)
connectpipe (stdin, p.stdin)
p.continueExecution()
source
share