q='''=; print "run\n"; sleep 3; print "exit\n"; __DATA__ '+%{ echo $q | sed -e 's/^[^;]*;/print "bash\n";/' | perl exit 0 ''' import subprocess child = subprocess.Popen("perl", stdin=subprocess.PIPE) child.stdin.write('print "python\n";' + q[3:]) child.wait() ''' } IO.popen("perl", "w") {|io| io.write('print "ruby\n";' + q[3..-1]) io.close_write } #'''