Created
July 28, 2015 15:58
-
-
Save michitomo/cad1f90b8df381ee1626 to your computer and use it in GitHub Desktop.
課題3-3 • 以下の仕様のシェル(コマンドインタプリタ)を作成してく ださい。以下の例では、$がUnixのシェル(bash等)のプロン プト,mysh>が作成したシェルのプロンプトを⽰します。 ª cdコマンド、exitコマンド(内部コマンド) ª 外部コマンドの実⾏(date等) ª パイプの実現(|で区切られた2つのコマンド)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
builtin = ['cd', 'exit'] | |
def execCd(cmd): | |
dir = cmd[3:] | |
try: | |
os.chdir(dir) | |
except: | |
print "Directory " + dir + " not found" | |
def execExit(): | |
sys.exit() | |
while True: | |
cmd = raw_input("mysh>") | |
if cmd.startswith("cd"): | |
execCd(cmd) | |
elif cmd.startswith("exit"): | |
execExit() | |
else: | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment