#!/usr/bin/python # -*- Coding: utf-8 -*- import os import sys while True: cmd = raw_input('$ ').strip() if cmd == "exit": sys.exit(0) if cmd == "": continue pid = os.fork() if pid ==0: argv = cmd.split() try: os.execvp(argv[0], argv) except OSError: print >>sys.stderr,\ "command not found: %s" \ % argv[0] sys.exit(0) else: print "Wait for child (%d)" % pid res = os.wait() print "(%d) child quit with %d" % res