#!/usr/bin/python # -*- Coding: utf-8 -*- import os import sys import threading, Queue def run(q, args): ret = os.spawnvp(os.P_WAIT, args[0], args) q.put(ret) while True: cmd = raw_input('$ ') if cmd.strip() == "exit": sys.exit(0) if cmd.strip() == "": continue argv = cmd.split() q = Queue.Queue() t = threading.Thread( name='subprocess', target=run, args=(q, argv) ) t.start() print "Wait for thread running (%s)" % argv[0] t.join() ret = q.get() print "Thread finished." print "Prosess returned with (%d)" % ret