我編寫了一個在linux中設置系統時間的函數。我寫下面的代碼:Python2設置時間錯誤
import time
import subprocess
def SetSystemTime(val):
try:
val = float(val)
except ValueError:
return
command = 'date -s"' + time.ctime(val) + '"'
subprocess.call(command)
在調用的,我得到:
File "crc.py", line 96, in SetSystemTime(0) File "crc.py", line 12, in SetSystemTime subprocess.call(command) File "/usr/lib/python2.7/subprocess.py", line 493, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 679, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1239, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory