导入os模块,用python模拟linux命令行 代码示例: import os for i in range(1000): cmd = input('[student@test ~]$ ') if cmd: if cmd == 'exit': print('logout') break else: print('run %s' %(cmd)) os.system(cmd) else: continue 运行效果