Enrico Franchi Homepage

Questo sito è obsoleto. La nuova versione di questa pagina è disponibile presso akropolix

This site is old. The new version of this page is available on akropolix

Spawn Shell

This is probably the most python way to write this code.

spawnshell.py (download)
#!/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
    args = cmd.split()
    res = os.spawnvp(os.P_WAIT, args[0], args)
    if res==127: print >>sys.stderr,\
        "command not found: %s" % args[0]
        

spawn takes care of creating the child and everything. This is Python, lad!

back

xhtml 1.1 CSS 2.1 RSS 2.0
Made with a Mac Made with BBEdit Made with Brain

All documentation is under FDL and all source code is under BSD, unless differently stated.

24-mar-06