代码如下:
"""
# _*_coding:utf-8_*_
Name:cmd.py
Date:1/14/19
Author:westos-sql
Connect:2910903196@qq.com
Desc:...
"""
import os
while True:
#for i in range(100):
cmd = input('[root@python55:~]# ')
if cmd:
if cmd == 'exit':
print('logout')
break
else:
print('Command is %s' %(cmd))
os.system(cmd)
else:
print('You must enter true Command')
continue
执行结果:
输入正确命令执行,返回结果,若输入exit则退出
####如果直接回车或者输入错误命令,结果如下: