#!/usr/bin/env python
import sys,subprocess,time,threading

if len(sys.argv) < 2:
	print "usage: wrapgdb <exe> [<args>]"
	sys.exit(-1)
       
class MyThread(threading.Thread):
  def run(self):
	self.proc = subprocess.Popen("gdb "+sys.argv[1], stdin=subprocess.PIPE, stdout=sys.stdout, stderr=sys.stderr, shell=True)

t = MyThread()
t.start()
time.sleep(3)
t.proc.stdin.write("run "+" ".join(sys.argv[2:])+"\n")
while True:
	l = sys.stdin.readline()
	t.proc.stdin.write(l)
	if l.strip() == "quit":		
		time.sleep(1)
		break

