python对文件的读写还是挺方便的,与linuxshell的交互变量需要转换一下才能用,这比较头疼!
1#coding=utf-82#!/usr/bin/python3importos4importtime5#python执行linux命令6os.system(':>./aa.py')7#人机交互输入8S = raw_input("input:")9os.environ['S']=str(S)10#把字符串S写入文件11output = open('./aa.py','a')12output.write(S)13#关闭文件14output.close()15#python中的思考时间16time.sleep(1)17#获取文件内容18f = open('./aa.py','r')19read =f.read()20#变量间的转换21os.environ['read']=str(read)22os.system('$read')23f.close()
24 var=os.popen('ifconfig').read( )
25PRint var