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!

Recommended Answers

All 4 Replies

You can write

with open("output.txt", "w") as fileout:

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!

give me the upvote buddy ;)

Please mark thread as solved.
good luck ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.