简单的python学习 ftruncate fsync +python执行linux命令(带参数传递)

来源:互联网 发布:销售网络分布图制作 编辑:程序博客网 时间:2024/06/05 01:09
#!/usr/bin/python
import os,sys

from sys import argv

#执行判断用法

if len(sys.argv) <> 4:
  print "Usage: " + sys.argv[0] + " filename clonename times"
  sys.exit(-1)


m=0;time=int(argv[3])
t=0;len=500

totlelen=100000


file=os.open(argv[1],os.O_RDWR|os.O_CREAT)

os.write(file,"1234this is test txt"*10000)


while m < time:

 cmd='leofs_clonecmd -f '+ argv[1]+' ccc'+str(m)

##下面这个是设置变量

 os.environ['cmd1']=cmd
 t+=len
 aa= totlelen - t
 os.ftruncate(file,aa)

 os.fsync(file)

#可以在linux中执行

 os.system('$cmd1')
 m+=1
阅读全文
0 0