Hi all professionals,

I uesd subprocess module to spawn a new process and then implement the command. The final result is the output via stdout.
Here is the code I wrote:

import subprocess
proc = subprocess.Popen('egrep \'^HTTP/\' *', shell=True, stdout=subprocess.PIPE,)
stdout_value = proc.communicate()[0]
print 'results:'
print stdout_value

And the results are: 302 Found 302 Found

My question is: How to convert/record these results into a file?

I appreciate all your responses and helps!

Gribouillis updated

Information like this will always need a callback into action. Therefore i thought of updating your script a little.

with open("logfile.txt","a+") as logfile:
     logfile.writelines(str(stdout_value)+"\n") # To get the newline. easy to work with that

In the end. You can read-in your data for further manipulation if needed.
I understand Gribouillis just gave you a simple pseudo just to give you the idea.


Thank all your responses.

I appreciate your kind-hearted help!

This question has already been answered. Start a new discussion instead.