import os
import time
import sys
print('''mode 1 : repeat to execute the command specific times
mode 2 : repeat to execute the command every specific seconds''')
mode=input('please input 1 0r 2 to select the mode:')
if int(mode) == 1:
command = input('the command that you want to execute:')
repeate_count = input('the count you want to repeat:')
for i in range(int(repeate_count)):
print(int(i+1))
output=os.system(command)
print('\n')
print('completed')
elif int(mode) == 2:
command = input('the command that you want to execute:')
repeate_sec = input('the seconds you want to repeat:')
print('type control + c to exit the script')
while True:
try:
while True:
os.system(command)
print('wait for %s s'%repeate_sec)
time.sleep(int(repeate_sec))
except KeyboardInterrupt:
print('received ctl+c')
print('stop the program ')
break
else:
print('something wrong happened ,stop the script')
sys.exit(1)
注意点:
两种模式
1.循环固定测试
2.每隔特定秒数执行一次 ,按ctrl+c结束代码。