daemon: Used the communicate() method to interact with subprocesses.

This commit is contained in:
Tom Goff 2016-01-29 16:43:46 -05:00
parent 6fb1eb9bd6
commit 0333c74bec
3 changed files with 8 additions and 21 deletions

View file

@ -27,13 +27,8 @@ def createngnode(type, hookstr, name=None):
cmd = [NGCTL_BIN, "-f", "-"]
cmdid = subprocess.Popen(cmd, stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
cmdid.stdin.write(ngcmd)
cmdid.stdin.close()
result = cmdid.stdout.read()
result += cmdid.stderr.read()
cmdid.stdout.close()
cmdid.stderr.close()
stderr = subprocess.STDOUT)
result, err = cmdid.communicate(input = ngcmd) # err will always be None
status = cmdid.wait()
if status > 0:
raise Exception, "error creating Netgraph node %s (%s): %s" % \

View file

@ -105,14 +105,10 @@ def cmdresult(args):
exit status and result string. stderr output
is folded into the stdout result string.
'''
cmdid = subprocess.Popen(args, stdin = subprocess.PIPE,
cmdid = subprocess.Popen(args, stdin = open(os.devnull, 'r'),
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
cmdid.stdin.close()
result = cmdid.stdout.read()
result += cmdid.stderr.read()
cmdid.stdout.close()
cmdid.stderr.close()
stderr = subprocess.STDOUT)
result, err = cmdid.communicate() # err will always be None
status = cmdid.wait()
return (status, result)

View file

@ -90,14 +90,10 @@ class PhysicalNode(PyCoreNode):
'''
os.chdir(self.nodedir)
# in Python 2.7 we can use subprocess.check_output() here
tmp = subprocess.Popen(args, stdin = subprocess.PIPE,
tmp = subprocess.Popen(args, stdin = open(os.devnull, 'r'),
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
result = tmp.stdout.read()
result += tmp.stderr.read()
tmp.stdin.close()
tmp.stdout.close()
tmp.stderr.close()
stderr = subprocess.STDOUT)
result, err = tmp.communicate() # err will always be None
status = tmp.wait()
return (status, result)