Python os.popen3() Examples
The following are 30
code examples of os.popen3().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: os.py From telegram-robot-rss with Mozilla Public License 2.0 | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #2
Source File: os.py From ImageFusion with MIT License | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #3
Source File: os.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #4
Source File: os.py From ImageFusion with MIT License | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #5
Source File: os.py From Computable with MIT License | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #6
Source File: os.py From BinderFilter with MIT License | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #7
Source File: os.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #8
Source File: os.py From oss-ftp with MIT License | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #9
Source File: os.py From datafari with Apache License 2.0 | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #10
Source File: collectd_ceph_storage.py From browbeat with Apache License 2.0 | 6 votes |
def run_command(self, command, check_output=True): """Run a command for this collectd plugin. Returns a tuple with command success and output or False and None for output. """ output = None try: if check_output: output = subprocess.check_output(command) else: stdin, stdout, stderr = os.popen3(' '.join(command)) output = stdout.read() except Exception as exc: collectd.error( 'collectd-ceph-storage: {} exception: {}'.format(command, exc)) collectd.error( 'collectd-ceph-storage: {} traceback: {}' .format(command, traceback.format_exc())) return False, None if output is None: collectd.error( 'collectd-ceph-storage: failed to {}: output is None' .format(command)) return False, None return True, output
Example #11
Source File: collectd_ceph_storage.py From browbeat with Apache License 2.0 | 6 votes |
def run_command(self, command, check_output=True): """Run a command for this collectd plugin. Returns a tuple with command success and output or False and None for output. """ output = None try: if check_output: output = subprocess.check_output(command) else: stdin, stdout, stderr = os.popen3(' '.join(command)) output = stdout.read() except Exception as exc: collectd.error( 'collectd-ceph-storage: {} exception: {}'.format(command, exc)) collectd.error( 'collectd-ceph-storage: {} traceback: {}' .format(command, traceback.format_exc())) return False, None if output is None: collectd.error( 'collectd-ceph-storage: failed to {}: output is None' .format(command)) return False, None return True, output
Example #12
Source File: testall.py From ironpython2 with Apache License 2.0 | 6 votes |
def __call__(self): try: import subprocess p = subprocess.Popen(self.argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) output, _ = p.communicate() rc = p.returncode except ImportError: # py2.3? fin, fout, ferr = os.popen3(" ".join(self.argv)) fin.close() output = fout.read() + ferr.read() fout.close() rc = ferr.close() if rc: base = os.path.basename(self.argv[1]) # See if we can detect and reconstruct an exception in the output. reconstituted = find_exception_in_output(output) if reconstituted is not None: raise reconstituted raise AssertionError("%s failed with exit code %s. Output is:\n%s" % (base, rc, output))
Example #13
Source File: os.py From pmatic with GNU General Public License v2.0 | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #14
Source File: os.py From ironpython2 with Apache License 2.0 | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #15
Source File: os.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #16
Source File: os.py From PhonePi_SampleServer with MIT License | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #17
Source File: os.py From meddle with MIT License | 6 votes |
def popen3(cmd, mode="t", bufsize=-1): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.""" import warnings msg = "os.popen3 is deprecated. Use the subprocess module." warnings.warn(msg, DeprecationWarning, stacklevel=2) import subprocess PIPE = subprocess.PIPE p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring), bufsize=bufsize, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) return p.stdin, p.stdout, p.stderr
Example #18
Source File: misc.py From CAAS with GNU General Public License v3.0 | 6 votes |
def start_local_analysis(file_path, cuckoo_path, kernel_analysis=False, timeout=300): command = cuckoo_path+"/utils/submit.py "+file_path+" --timeout "+str(timeout) if kernel_analysis != False: command = command + " --options kernel_analysis=yes" stdin,stdout,stderr = os.popen3(command) is_task = 0 if stdout: stdout_line = stdout.read() if stderr: stderr_line = stderr.read() log.debug("Local command output STDOUT: "+stdout_line) log.debug("Local command output STDERR: "+stderr_line) if stdout_line != "": id_task = int(stdout_line.split(" ")[-1]) else: log.err("Local submit failed, stderr: "+stderr_line) return id_task
Example #19
Source File: util.py From pywebsocket with BSD 3-Clause "New" or "Revised" License | 6 votes |
def wrap_popen3_for_win(cygwin_path): """Wrap popen3 to support #!-script on Windows. Args: cygwin_path: path for cygwin binary if command path is needed to be translated. None if no translation required. """ __orig_popen3 = os.popen3 def __wrap_popen3(cmd, mode='t', bufsize=-1): cmdline = cmd.split(' ') interp = get_script_interp(cmdline[0], cygwin_path) if interp: cmd = interp + ' ' + cmd return __orig_popen3(cmd, mode, bufsize) os.popen3 = __wrap_popen3
Example #20
Source File: awmstools.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def readProcess(cmd, *args): r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the exit code (unlike popen2, exit is 0 if no problems occured (for some bizarre reason popen2 returns None... <sigh>). FIXME: only works for UNIX; handling of signalled processes. """ import popen2 BUFSIZE=1024 import select popen = popen2.Popen3((cmd,) + args, capturestderr=True) which = {id(popen.fromchild): [], id(popen.childerr): []} select = Result(select.select) read = Result(os.read) try: popen.tochild.close() # XXX make sure we're not waiting forever while select([popen.fromchild, popen.childerr], [], []): readSomething = False for f in select.result[0]: while read(f.fileno(), BUFSIZE): which[id(f)].append(read.result) readSomething = True if not readSomething: break out, err = ["".join(which[id(f)]) for f in [popen.fromchild, popen.childerr]] returncode = popen.wait() if os.WIFEXITED(returncode): exit = os.WEXITSTATUS(returncode) else: exit = returncode or 1 # HACK: ensure non-zero finally: try: popen.fromchild.close() finally: popen.childerr.close() return out or "", err or "", exit
Example #21
Source File: awmstools.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def readProcess(cmd, *args): r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the exit code (unlike popen2, exit is 0 if no problems occured (for some bizarre reason popen2 returns None... <sigh>). FIXME: only works for UNIX; handling of signalled processes. """ import popen2 BUFSIZE=1024 import select popen = popen2.Popen3((cmd,) + args, capturestderr=True) which = {id(popen.fromchild): [], id(popen.childerr): []} select = Result(select.select) read = Result(os.read) try: popen.tochild.close() # XXX make sure we're not waiting forever while select([popen.fromchild, popen.childerr], [], []): readSomething = False for f in select.result[0]: while read(f.fileno(), BUFSIZE): which[id(f)].append(read.result) readSomething = True if not readSomething: break out, err = ["".join(which[id(f)]) for f in [popen.fromchild, popen.childerr]] returncode = popen.wait() if os.WIFEXITED(returncode): exit = os.WEXITSTATUS(returncode) else: exit = returncode or 1 # HACK: ensure non-zero finally: try: popen.fromchild.close() finally: popen.childerr.close() return out or "", err or "", exit
Example #22
Source File: backend_ps.py From ImageFusion with MIT License | 5 votes |
def get_bbox(tmpfile, bbox): """ Use ghostscript's bbox device to find the center of the bounding box. Return an appropriately sized bbox centered around that point. A bit of a hack. """ outfile = tmpfile + '.output' gs_exe = ps_backend_helper.gs_exe command = '%s -dBATCH -dNOPAUSE -sDEVICE=bbox "%s"' %\ (gs_exe, tmpfile) verbose.report(command, 'debug') stdin, stdout, stderr = os.popen3(command) verbose.report(stdout.read(), 'debug-annoying') bbox_info = stderr.read() verbose.report(bbox_info, 'helpful') bbox_found = re.search('%%HiResBoundingBox: .*', bbox_info) if bbox_found: bbox_info = bbox_found.group() else: raise RuntimeError('Ghostscript was not able to extract a bounding box.\ Here is the Ghostscript output:\n\n%s'% bbox_info) l, b, r, t = [float(i) for i in bbox_info.split()[-4:]] # this is a hack to deal with the fact that ghostscript does not return the # intended bbox, but a tight bbox. For now, we just center the ink in the # intended bbox. This is not ideal, users may intend the ink to not be # centered. if bbox is None: l, b, r, t = (l-1, b-1, r+1, t+1) else: x = (l+r)/2 y = (b+t)/2 dx = (bbox[2]-bbox[0])/2 dy = (bbox[3]-bbox[1])/2 l,b,r,t = (x-dx, y-dy, x+dx, y+dy) bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, np.ceil(r), np.ceil(t)) hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t) return '\n'.join([bbox_info, hires_bbox_info])
Example #23
Source File: popen2.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def popen3(cmd, bufsize=-1, mode='t'): """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdout, child_stdin, child_stderr) are returned.""" w, r, e = os.popen3(cmd, mode, bufsize) return r, w, e
Example #24
Source File: awmstools.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def readProcess(cmd, *args): r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the exit code (unlike popen2, exit is 0 if no problems occured (for some bizarre reason popen2 returns None... <sigh>). FIXME: only works for UNIX; handling of signalled processes. """ import popen2 BUFSIZE=1024 import select popen = popen2.Popen3((cmd,) + args, capturestderr=True) which = {id(popen.fromchild): [], id(popen.childerr): []} select = Result(select.select) read = Result(os.read) try: popen.tochild.close() # XXX make sure we're not waiting forever while select([popen.fromchild, popen.childerr], [], []): readSomething = False for f in select.result[0]: while read(f.fileno(), BUFSIZE): which[id(f)].append(read.result) readSomething = True if not readSomething: break out, err = ["".join(which[id(f)]) for f in [popen.fromchild, popen.childerr]] returncode = popen.wait() if os.WIFEXITED(returncode): exit = os.WEXITSTATUS(returncode) else: exit = returncode or 1 # HACK: ensure non-zero finally: try: popen.fromchild.close() finally: popen.childerr.close() return out or "", err or "", exit
Example #25
Source File: awmstools.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def readProcess(cmd, *args): r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the exit code (unlike popen2, exit is 0 if no problems occured (for some bizarre reason popen2 returns None... <sigh>). FIXME: only works for UNIX; handling of signalled processes. """ import popen2 BUFSIZE=1024 import select popen = popen2.Popen3((cmd,) + args, capturestderr=True) which = {id(popen.fromchild): [], id(popen.childerr): []} select = Result(select.select) read = Result(os.read) try: popen.tochild.close() # XXX make sure we're not waiting forever while select([popen.fromchild, popen.childerr], [], []): readSomething = False for f in select.result[0]: while read(f.fileno(), BUFSIZE): which[id(f)].append(read.result) readSomething = True if not readSomething: break out, err = ["".join(which[id(f)]) for f in [popen.fromchild, popen.childerr]] returncode = popen.wait() if os.WIFEXITED(returncode): exit = os.WEXITSTATUS(returncode) else: exit = returncode or 1 # HACK: ensure non-zero finally: try: popen.fromchild.close() finally: popen.childerr.close() return out or "", err or "", exit
Example #26
Source File: awmstools.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def readProcess(cmd, *args): r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the exit code (unlike popen2, exit is 0 if no problems occured (for some bizarre reason popen2 returns None... <sigh>). FIXME: only works for UNIX; handling of signalled processes. """ import popen2 BUFSIZE=1024 import select popen = popen2.Popen3((cmd,) + args, capturestderr=True) which = {id(popen.fromchild): [], id(popen.childerr): []} select = Result(select.select) read = Result(os.read) try: popen.tochild.close() # XXX make sure we're not waiting forever while select([popen.fromchild, popen.childerr], [], []): readSomething = False for f in select.result[0]: while read(f.fileno(), BUFSIZE): which[id(f)].append(read.result) readSomething = True if not readSomething: break out, err = ["".join(which[id(f)]) for f in [popen.fromchild, popen.childerr]] returncode = popen.wait() if os.WIFEXITED(returncode): exit = os.WEXITSTATUS(returncode) else: exit = returncode or 1 # HACK: ensure non-zero finally: try: popen.fromchild.close() finally: popen.childerr.close() return out or "", err or "", exit
Example #27
Source File: awmstools.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def readProcess(cmd, *args): r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the exit code (unlike popen2, exit is 0 if no problems occured (for some bizarre reason popen2 returns None... <sigh>). FIXME: only works for UNIX; handling of signalled processes. """ import popen2 BUFSIZE=1024 import select popen = popen2.Popen3((cmd,) + args, capturestderr=True) which = {id(popen.fromchild): [], id(popen.childerr): []} select = Result(select.select) read = Result(os.read) try: popen.tochild.close() # XXX make sure we're not waiting forever while select([popen.fromchild, popen.childerr], [], []): readSomething = False for f in select.result[0]: while read(f.fileno(), BUFSIZE): which[id(f)].append(read.result) readSomething = True if not readSomething: break out, err = ["".join(which[id(f)]) for f in [popen.fromchild, popen.childerr]] returncode = popen.wait() if os.WIFEXITED(returncode): exit = os.WEXITSTATUS(returncode) else: exit = returncode or 1 # HACK: ensure non-zero finally: try: popen.fromchild.close() finally: popen.childerr.close() return out or "", err or "", exit
Example #28
Source File: awmstools.py From DeepLearning_Wavelet-LSTM with MIT License | 5 votes |
def readProcess(cmd, *args): r"""Similar to `os.popen3`, but returns 2 strings (stdin, stdout) and the exit code (unlike popen2, exit is 0 if no problems occured (for some bizarre reason popen2 returns None... <sigh>). FIXME: only works for UNIX; handling of signalled processes. """ import popen2 BUFSIZE=1024 import select popen = popen2.Popen3((cmd,) + args, capturestderr=True) which = {id(popen.fromchild): [], id(popen.childerr): []} select = Result(select.select) read = Result(os.read) try: popen.tochild.close() # XXX make sure we're not waiting forever while select([popen.fromchild, popen.childerr], [], []): readSomething = False for f in select.result[0]: while read(f.fileno(), BUFSIZE): which[id(f)].append(read.result) readSomething = True if not readSomething: break out, err = ["".join(which[id(f)]) for f in [popen.fromchild, popen.childerr]] returncode = popen.wait() if os.WIFEXITED(returncode): exit = os.WEXITSTATUS(returncode) else: exit = returncode or 1 # HACK: ensure non-zero finally: try: popen.fromchild.close() finally: popen.childerr.close() return out or "", err or "", exit
Example #29
Source File: escope.py From collection with MIT License | 5 votes |
def redirect(args, reader, combine = True): import subprocess if 'Popen' in subprocess.__dict__: p = subprocess.Popen(args, shell = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = combine and subprocess.STDOUT or subprocess.PIPE) stdin, stdout, stderr = p.stdin, p.stdout, p.stderr if combine: stderr = None else: p = None if combine == False: stdin, stdout, stderr = os.popen3(cmd) else: stdin, stdout = os.popen4(cmd) stderr = None stdin.close() while 1: text = stdout.readline() if text == '': break reader('stdout', text) while stderr != None: text = stderr.readline() if text == '': break reader('stderr', text) stdout.close() if stderr: stderr.close() retcode = None if p: retcode = p.wait() return retcode #---------------------------------------------------------------------- # configure #----------------------------------------------------------------------
Example #30
Source File: run.py From ironpython3 with Apache License 2.0 | 5 votes |
def run_one_command(*args): """runs a single command, exiting if it doesn't return 0, redirecting std out""" cmd_line = '"' + executable + '" '.join(args) inp, out, err = os.popen3(cmd_line) print(cmd_line) output, err = multireader(out, err) res = out.close() if res: print('%d running %s failed' % (res, cmd_line)) print('output was', output) print('err', err) return output, err, res