subprocess-how to suppress the stdout

A

alf

Hi,
I use subprocess to execute another program but need to suppress its stdout.

I can achieve it by using Popen(...,stdout=subprocess.PIPE,...) but
wonder where the all stdout actually goes. Is it buffered (to eventually
fill up)or just discarded?

Or there is a better solution ...

Thx, alf
 
A

alf

Fredrik said:
it ends up in a pipe buffer, yes.




/dev/null is your friend:

Popen(..., stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT, ...)

I am forced to use win32 :-( plus it needs to be platform independent ...
 
F

Fredrik Lundh

alf said:
I can achieve it by using Popen(...,stdout=subprocess.PIPE,...) but
wonder where the all stdout actually goes. Is it buffered (to eventually
fill up)

it ends up in a pipe buffer, yes.
Or there is a better solution ...

/dev/null is your friend:

Popen(..., stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT, ...)

</F>
 
F

Fredrik Lundh

alf said:
I am forced to use win32 :-( plus it needs to be platform independent ...

alright, os.devnull is your friend:

Popen(..., stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT, ...)

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top