だから私はPythonでシェルを書いています、そしてファイル名はjsh.py
です。コードを実行すると、何らかの理由で機能しません。ウィンドウがポップアップしますが、すぐに閉じます。私のコードで何が摩耗していますか?
import os
import random
import time
import path
import string
import sys
commandAvail = 'ls where chdir mk mkdir cp mv rm rmdir view ext shutdown edit unix dos man-all man-unix man-dos'
commandAvailUnix = 'exec permission group'
commandAvailDos = ' '
print('Welcome to jsh alpha 1!')
commandPlatform = input('System: (UNIX/DOS):')
commandLine()
def commandLine():
while 1 == 1:
command = input('$ ')
if command in commandAvail:
if command.startswith('ls'):
commandKeyword = 'ls'
commandOptions = command - commandKeyword
ls(commandOptions)
elif command.startswith('where'):
commandKeyword = 'where'
commandOptions = command - commandKeyword
where()
elif command.startswith('chdir'):
commandKeyword = 'chdir'
commandOptions = command - commandKeyword
chdir()
elif command.startswith('mk'):
commandKeyword = 'mk'
commandOptions = command - commandKeyword
mk()
elif command.startswith('mkdir'):
commandKeyword = 'mkdir'
commandOptions = command - commandKeyword
mkdir()
elif command.startswith('cp'):
commandKeyword = 'cp'
commandOptions = command - commandKeyword
cp()
elif command.startswith('mv'):
commandKeyword = 'mv'
commandOptions = command - commandKeyword
mv()
elif command.startswith('rm'):
commandKeyword = 'rm'
commandOptions = command - commandKeyword
rm()
elif command.startswith('rmdir'):
commandKeyword = 'rmdir'
commandOptions = command - commandKeyword
rm()
elif command.startswith('view'):
commandKeyword = 'view'
commandOptions = command - commandKeyword
rm()
elif command.startswith('edit'):
commandKeyword = 'edit'
commandOptions = command - commandKeyword
edit()
elif command == 'man-all':
print('Commands that work for all underlying platforms:')
print(commandAvail)
elif command == 'man-unix':
print('Commands that only work on Unix systems:')
print(commandAvailUnix)
elif command == 'man-dos'
print('Commands that only work on DOS systems:')
print(commandAvailDos)
elif command.startswith('unix'):
commandType = 'unix'
unix()
elif command.startswith('dos'):
commandType = 'dos'
dos()
elif command.startswith('ext'):
commandKeyword = 'ext'
commandOptions = command - commandKeyword
ext()
elif command == 'shutdown':
sys.quit(0)
else:
print('jsh has experienced an internal error and has to shutdown.')
sys.quit(10)
else:
print('Command \'' + command + '\' not recognized as internal or external.')
def ls(options):
if commandPlatform == 'UNIX':
os.system('ls' + options)
else:
os.system('dir' + options)
commandLine()