Portable way to refer to the null device?
nick at stinemates.org
nick at stinemates.org
Sat Feb 7 18:56:45 EST 2009
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,
> 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
More information about the Python-list
mailing list