#coding:utf-8
import os
import time

def print_ts(message):
    print "[%s] %s"%(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message)###转为为2016-09-08 13:36:32时间格式

def run(interval, command):
    print_ts("-"*100)
    print_ts("Command %s"%command)
    print_ts("Starting every %s seconds."%interval)
    print_ts("-"*100)

    while True:
        try:
            # sleep for the remaining seconds of interval,http://www.sharejs.com
            print_ts("Sleeping until %s (%s seconds)..."%((time.ctime(time.time()+interval)), interval))
            time.sleep(interval)
            print_ts("Starting command.")

            # execute the command
            status = os.system(command)
            print_ts("-"*100)
            print_ts("Command status = %s."%status)
        except Exception,e:
            print e

if __name__=="__main__":
    interval = 500
    command = r"ipconfig"
    run(interval, command)

  

相关文章:

  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-14
  • 2022-01-18
  • 2021-06-26
  • 2022-03-07
相关资源
相似解决方案