in reply to Simulating popen()

I'd use the Expect module. Only because if you're interacting with this external process, there's lots of nitpicky details that Expect will take care of for you. This frees you to think about the conversation and not worry too much about buffering, deadlock, ptys, etc..