import sys, os, datetime, time, urllib
from subprocess import *
List_SP_Servers=["toto1","toto2","toto3"]
ListTraceFile_SP_Servers=["c:\\\\dic1\\\\udic1\\\\file1.txt","c:\\\\dic1\\\\udic1\\\\file2.txt"]
for l__sp in List_SP_Servers:
try:
print '\n--------'+str(l__sp)+'--------'
for l__traces in ListTraceFile_SP_Servers:
#l__cmd1 = '['+'\"psexec\",\"\\\\'+l__sp+'\",'+'\"-nobanner\"'+',\"ls\",\"-al\"'+',"'+l__traces+'\"'+']'
#l__cmd1 = '(['+'\"psexec\",\"\\\\'+l__sp+'\",'+'\"-nobanner\"'+',\"ls\",\"-al\"'+',"'+l__traces+'\"'+'],shell=True,stdout=PIPE).communicate()[0]'
#print l__cmd1
#output1=popen(l__cmd1,shell=True,stdout=PIPE).communicate()[0]
#l__cmd1 = "[\"C:\\Tools\\Sysinternalsuite\\psexec\",\"\\\\\\"%s"\",\"-nobanner\",\"ls\",\"-al\","%s"\"]" % (l__sp,l__traces)
#print 'La vies est -->'+l__cmd1
#l__cmd1_WithCall = "\'psexec\",\"\\\\\\"%s"\",\"-nobanner\",\"ls\",\"-al\" "%s"\'" % (l__sp,l__traces)
l__cmd1_WithCall = "\'psexec \\\%s -nobanner ls -al %s\'" % (l__sp,l__traces)
#l__cmd1_WithCall = "\"psexec\",\"\\\%s,\"ls\",\"-al\",%s" % (l__sp,l__traces)
print 'l__cmd1_WithCall-->',l__cmd1_WithCall
p5=call(l__cmd1_WithCall,shell=True)
print '---->',p5,'<-----'
except:
print '\n'+l__sp+' Can\'t reach it !\n'
上面的代码给出了错误,因为我试图将某些文件的最后修改日期从Windows服务器转移到远程Windows服务器。 我使用psexec在Windows上,但也许他们是获取此类信息的其他解决方案。
我尝试使用subprocess.call, subprocess.popen, subprocess.check_out
并且都给了我错误,但是当我尝试在cmd上直接输入命令时,它运行正常。
答案 0 :(得分:2)
为了最后一次在Windows中修改文件,您可以使用下面的代码
import os,datetime
timestamp = os.stat(PATH_OF_FILE).st_ctime
readable = datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
首先获得时间戳并可读取将其转换为日期