Did I find the right examples for you? yes no Crawl my project Python Jobs
All Samples(1) | Call(1) | Derive(0) | Import(0)
def execute(commandList, printOutput=False, nohup=False): logger = logging.getLogger() strCommandList = [] for c in commandList: strCommandList.append(str(c)) if logger.isEnabledFor(logging.DEBUG): logger.debug("Run command [%s]", " ".join(strCommandList)) if nohup: with open("/dev/null", "rw") as nullStream: p = subprocess.Popen(strCommandList, stdout=nullStream, stderr=nullStream, stdin=nullStream) r = p.wait() if logger.isEnabledFor(logging.DEBUG): logger.debug("Run command [%s], Return %d", " ".join(strCommandList), r) if r != 0: raise IOError("returned %d"%r) return p = subprocess.Popen(strCommandList, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # This may cause OutOfMemory. # if printOutput: # print >> sys.stdout, p.stdout.read() # p.wait() # if printOutput: # print >> sys.stderr, p.stderr.read() # p.stdout.close() # p.stderr.close() try: # When printOuput, this child process can become zombie when the child process fork another process and exit. # Probably this is caused by the shared stdout object, which is occupied by the new forked process. if printOutput: while True: line = p.stdout.readline() if not line: break print line, r = p.wait() if logger.isEnabledFor(logging.DEBUG): logger.debug("Run command [%s], Return %d", " ".join(strCommandList), r) if r != 0 or printOutput: errMessage = p.stderr.readline() errline = errMessage while True: if errline: print errline, else: break errline = p.stderr.readline() if r !=0 : raise IOError(errMessage.strip()) finally: p.stderr.close() p.stdout.close()
for arg in args: command.append(arg) shellutil.execute(command, nohup=True)