Revision 113b55aa

b/lib/utils.py
27 27
import os
28 28
import sha
29 29
import time
30
import popen2
30
import subprocess
31 31
import re
32 32
import socket
33 33
import tempfile
......
204 204
  """
205 205
  if isinstance(cmd, list):
206 206
    cmd = [str(val) for val in cmd]
207
  child = popen2.Popen3(cmd, capturestderr=True)
208

  
209
  child.tochild.close()
210
  out = child.fromchild.read()
211
  err = child.childerr.read()
207
    strcmd = " ".join(cmd)
208
    shell = False
209
  else:
210
    strcmd = cmd
211
    shell = True
212
  child = subprocess.Popen(cmd, shell=shell,
213
                           stderr=subprocess.PIPE,
214
                           stdout=subprocess.PIPE,
215
                           stdin=subprocess.PIPE,
216
                           close_fds=True)
217

  
218
  child.stdin.close()
219
  out = child.stdout.read()
220
  err = child.stderr.read()
212 221

  
213 222
  status = child.wait()
214
  if os.WIFSIGNALED(status):
215
    signal = os.WTERMSIG(status)
216
  else:
223
  if status >= 0:
224
    exitcode = status
217 225
    signal = None
218
  if os.WIFEXITED(status):
219
    exitcode = os.WEXITSTATUS(status)
220 226
  else:
221 227
    exitcode = None
222

  
223
  if isinstance(cmd, list):
224
    strcmd = " ".join(cmd)
225
  else:
226
    strcmd = str(cmd)
228
    signal = -status
227 229

  
228 230
  return RunResult(exitcode, signal, out, err, strcmd)
229 231

  

Also available in: Unified diff