Portable way to refer to the null device?
exarkun at divmod.com
Sun Feb 8 01:34:04 CET 2009
On Sat, 7 Feb 2009 15:56:45 -0800, nick at stinemates.org wrote:
>On Fri, Feb 06, 2009 at 07:32:20PM -0800, Roy Smith wrote:
>> 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,
>> stdout=open(outfile, 'w'),
>> stderr=open(errfile, 'w'),
>> 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:
> def write(self, str):
I bet this won't work. It needs to be a "real" file - have a file
descriptor or a handle or something.
Instead, try opening os.devnull.
More information about the Python-list