close_fds=True by default
This commit is contained in:
parent
0bd359f89d
commit
2cd77e07a2
5 changed files with 13 additions and 14 deletions
|
|
@ -135,7 +135,7 @@ def get_interface():
|
|||
if sys.platform == 'darwin':
|
||||
#cmd = ['/usr/sbin/netstat', '-rn']
|
||||
cmd = ['/sbin/route', '-n', 'get', 'default']
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
|
||||
stdout, stderr = p.communicate()
|
||||
interface = [[p.strip() for p in s.split(':', 1)] for s in stdout.strip().split('\n') if 'interface' in s]
|
||||
if interface:
|
||||
|
|
@ -148,21 +148,21 @@ def get_local_ipv4():
|
|||
ip = None
|
||||
if sys.platform == 'darwin':
|
||||
cmd = ['/sbin/route', '-n', 'get', 'default']
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
|
||||
stdout, stderr = p.communicate()
|
||||
interface = [[p.strip() for p in s.split(':', 1)]
|
||||
for s in stdout.strip().split('\n') if 'interface' in s]
|
||||
if interface:
|
||||
interface = interface[0][1]
|
||||
cmd = ['ifconfig', interface]
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
|
||||
stdout, stderr = p.communicate()
|
||||
ips = [l for l in stdout.split('\n') if 'inet ' in l]
|
||||
if ips:
|
||||
ip = ips[0].strip().split(' ')[1]
|
||||
else:
|
||||
cmd = ['ip', 'route', 'show']
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
|
||||
stdout, stderr = p.communicate()
|
||||
local = [l for l in stdout.split('\n') if 'default' in l]
|
||||
if local:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue