[Python]How to convert/record the output from subprocess into a file -


i using subprocess module, popen class output results like:

063.245.209.093.00080-128.192.076.180.01039:http/1.1 302 found 063.245.209.093.00080-128.192.076.180.01040:http/1.1 302 found

and here script wrote:

import subprocess, shlex, fileinput,filecmp proc = subprocess.popen('egrep \'^http/\' *', shell=true,      stdin=subprocess.pipe, stdout=subprocess.pipe,) stdout_value = proc.communicate()[0] print 'results:' print stdout_value 

my question is: how convert/record results stdout file?

i appreciate responses , helps!

import subprocess import glob  def egrep(pattern, *files):     """ runs egrep on files , returns entire result string """     cmd = ['egrep', pattern]     filespec in files:         cmd.extend(glob.glob(filespec))     proc = subprocess.popen(cmd, stdout=subprocess.pipe)     return proc.communicate()[0]  results = egrep(r'^http/', '*') print 'results:' print results  # write file open('result_file.txt', 'w') f:     f.write(results) 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -