Portable way to refer to the null device?

R

Roy Smith

I need to run a command using subprocess.Popen() and have stdin
connected to the null device. On unix, I would do:

self.process = subprocess.Popen(argv,
env=new_env,
stdout=open(outfile, 'w'),
stderr=open(errfile, 'w'),
stdin=open('/dev/null')
)

but that's not portable to windows. Does Python have a portable way
to get a file object connected to the null device, regardless of what
operating system you're running on?
 
N

nick

I need to run a command using subprocess.Popen() and have stdin
connected to the null device. On unix, I would do:

self.process = subprocess.Popen(argv,
env=new_env,
stdout=open(outfile, 'w'),
stderr=open(errfile, 'w'),
stdin=open('/dev/null')
)

but that's not portable to windows. Does Python have a portable way
to get a file object connected to the null device, regardless of what
operating system you're running on?

I normally just implement my own object:

class DevNull:
def write(self, str):
pass
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top