p = subprocess.Popen(['ruby', 'ruby_program.rb'], stdin=subprocess.PIPE,
    stdout=subprocess.PIPE)
ruby_question = p.stdout.readline()
answer = calculate_answer(ruby_question)
p.stdin.write(answer)
How do I take the output of one program and use it as the input of another?