diff --git a/pingnet.py b/pingnet.py index 4d381f7..4340560 100755 --- a/pingnet.py +++ b/pingnet.py @@ -64,10 +64,11 @@ class Pinger(threading.Thread): break def ping(self, host): - p = subprocess.Popen(['ping', '-c', '1', '-W', '1', host], - stdin=open(os.devnull), - stdout=open(os.devnull, 'w'), - stderr=subprocess.STDOUT) + with open(os.devnull, 'r+') as nul: + p = subprocess.Popen(['ping', '-c', '1', '-W', '1', host], + stdin=nul, + stdout=nul, + stderr=subprocess.STDOUT) p.wait() if p.returncode == 0: if not self.quiet: