A small Python Shell

xiaoxiao2021-03-06  132

#! / usr / bin / python

# - * - CODING: CP936 - * -

#############################################################

# Written by caocao # #

# caocao@eastday.com # #

# http://nethermit.yeah.net #

#############################################################

IMPORT OS

Import sys

IMPORT STRING

IMPORT RE

Print "Written by Caocao"

Print "caocao@eastday.com"

Print "http://nethermit.yeah.net"

Print

if os.name == "NT":

Print "OS: Windows NT"

Else:

Print "OS: Unknown"

Print "Python Shell Version 1.0"

Print

While True:

TRY:

Command = string.strip (Raw_INPUT ("PS" OS.Getcwd () ">"), "")

CommandLow = String.Lower (Command)

Except EofError:

Break

Else:

if CommandLow == "exit" or commandlow == "quit":

Break

Elif commandlow == "":

Continue

Elif Re.match ("^ [A-Z] {1}: $", command, re.i)! = none:

TRY:

Os.chdir (Command)

Except Oserror:

Print "No Such File or Directory"

Elif Re.match ("^ CD (. ) $", Command, Re.i)! = None:

MatchObject = Re.Search ("^ CD (. ) $", Command, Re.i)

if MatchObject! = None:

TRY:

Os.chdir (MatchObject.group (1))

Except Oserror:

Print "No Such File or Directory"

Else:

Print "Bad Command"

Else:

Os.System (Command)

Print

Print "Byebye!"

转载请注明原文地址:https://www.9cbs.com/read-99841.html

New Post(0)