Python os.WEXITSTATUS Examples
The following are 30
code examples of os.WEXITSTATUS().
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: gmock_test_utils.py From training_results_v0.5 with Apache License 2.0 | 6 votes |
def GetExitStatus(exit_code): """Returns the argument to exit(), or -1 if exit() wasn't called. Args: exit_code: the result value of os.system(command). """ if os.name == 'nt': # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns # the argument to exit() directly. return exit_code else: # On Unix, os.WEXITSTATUS() must be used to extract the exit status # from the result of os.system(). if os.WIFEXITED(exit_code): return os.WEXITSTATUS(exit_code) else: return -1 # Suppresses the "Invalid const name" lint complaint # pylint: disable-msg=C6409 # Exposes utilities from gtest_test_utils.
Example #2
Source File: test_mail.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def exitStatus(self, code): """ Construct a status from the given exit code. @type code: L{int} between 0 and 255 inclusive. @param code: The exit status which the code will represent. @rtype: L{int} @return: A status integer for the given exit code. """ # /* Macros for constructing status values. */ # #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) status = (code << 8) | 0 # Sanity check self.assertTrue(os.WIFEXITED(status)) self.assertEqual(os.WEXITSTATUS(status), code) self.assertFalse(os.WIFSIGNALED(status)) return status
Example #3
Source File: forking.py From BinderFilter with MIT License | 6 votes |
def poll(self, flag=os.WNOHANG): if self.returncode is None: while True: try: pid, sts = os.waitpid(self.pid, flag) except os.error as e: if e.errno == errno.EINTR: continue # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None else: break if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) else: assert os.WIFEXITED(sts) self.returncode = os.WEXITSTATUS(sts) return self.returncode
Example #4
Source File: setup.py From pycopia with Apache License 2.0 | 6 votes |
def _do_commands(name, cmds, root): # use sudo on Linux and possibly other platforms. On Windows it's # assumed you're running as Administrator (everybody does it...) if root and sys.platform not in ("win32", "cli"): sudo = "sudo " else: sudo = "" cmd = "%s%s setup.py %s" % (sudo, sys.executable, " ".join(cmds)) print("========", name, "==", cmd) rv = False os.chdir(name) try: rv = WEXITSTATUS(os.system(cmd)) == 0 finally: os.chdir("..") print("====================== END", name, "\n") return rv
Example #5
Source File: setup.py From pycopia with Apache License 2.0 | 6 votes |
def _do_scripts(name, scriptdir, root=False): if root and sys.platform not in ("win32", "cli"): sudo = "sudo " else: sudo = "" os.chdir(name) rv = True try: if os.path.isdir("bin"): if sys.platform == "darwin": cmd = "%scp -a bin/* %s" % (sudo, scriptdir) else: cmd = "%scp -dR --preserve=mode bin/* %s" % (sudo, scriptdir) print("======== SCRIPTS", name, "==", cmd) rv = WEXITSTATUS(os.system(cmd)) == 0 finally: os.chdir("..") print("====================== END SCRIPTS", name) return rv
Example #6
Source File: setup.py From pycopia with Apache License 2.0 | 6 votes |
def do_squash(name): if not _check_rsync(): print("Squash requires rsync tool to be installed.") return False if not os.path.isdir(PYCOPIA_SQUASH): os.makedirs(PYCOPIA_SQUASH) os.chdir(name) uname = os.uname() bin_dir = os.path.join("build", "lib.%s-%s-%s" % (uname[0].lower(), uname[4], sys.version[:3])) # e.g: build/lib.linux-x86_64-2.5/pycopia print("======== SQUASH", name, "to", PYCOPIA_SQUASH) try: if WEXITSTATUS(os.system("%s setup.py build" % (sys.executable,))) != 0: return False for pydir in ("build/lib", bin_dir): if os.path.isdir(pydir): cmd = "rsync -azvu %s/ %s" % (pydir, PYCOPIA_SQUASH) if WEXITSTATUS(os.system(cmd)) != 0: return False finally: os.chdir("..") _null_init(PYCOPIA_SQUASH) print("====================== END", name, "squashed into", PYCOPIA_SQUASH, "\n") return True
Example #7
Source File: forkedfunc.py From python-netsurv with MIT License | 6 votes |
def waitfinish(self, waiter=os.waitpid): pid, systemstatus = waiter(self.pid, 0) if systemstatus: if os.WIFSIGNALED(systemstatus): exitstatus = os.WTERMSIG(systemstatus) + 128 else: exitstatus = os.WEXITSTATUS(systemstatus) else: exitstatus = 0 signal = systemstatus & 0x7f if not exitstatus and not signal: retval = self.RETVAL.open('rb') try: retval_data = retval.read() finally: retval.close() retval = marshal.loads(retval_data) else: retval = None stdout = self.STDOUT.read() stderr = self.STDERR.read() self._removetemp() return Result(exitstatus, signal, retval, stdout, stderr)
Example #8
Source File: forkedfunc.py From python-netsurv with MIT License | 6 votes |
def waitfinish(self, waiter=os.waitpid): pid, systemstatus = waiter(self.pid, 0) if systemstatus: if os.WIFSIGNALED(systemstatus): exitstatus = os.WTERMSIG(systemstatus) + 128 else: exitstatus = os.WEXITSTATUS(systemstatus) else: exitstatus = 0 signal = systemstatus & 0x7f if not exitstatus and not signal: retval = self.RETVAL.open('rb') try: retval_data = retval.read() finally: retval.close() retval = marshal.loads(retval_data) else: retval = None stdout = self.STDOUT.read() stderr = self.STDERR.read() self._removetemp() return Result(exitstatus, signal, retval, stdout, stderr)
Example #9
Source File: gtest_test_utils.py From training_results_v0.5 with Apache License 2.0 | 6 votes |
def GetExitStatus(exit_code): """Returns the argument to exit(), or -1 if exit() wasn't called. Args: exit_code: the result value of os.system(command). """ if os.name == 'nt': # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns # the argument to exit() directly. return exit_code else: # On Unix, os.WEXITSTATUS() must be used to extract the exit status # from the result of os.system(). if os.WIFEXITED(exit_code): return os.WEXITSTATUS(exit_code) else: return -1
Example #10
Source File: posix.py From nightmare with GNU General Public License v2.0 | 6 votes |
def platformProcessEvent(self, status): if os.WIFEXITED(status): tid = self.getMeta("ThreadId", -1) if tid != self.getPid(): # Set the selected thread ID to the pid cause # the old one's invalid if tid in self.pthreads: self.pthreads.remove(tid) self.setMeta("ThreadId", self.getPid()) self._fireExitThread(tid, os.WEXITSTATUS(status)) else: self._fireExit(os.WEXITSTATUS(status)) elif os.WIFSIGNALED(status): self.setMeta("ExitCode", os.WTERMSIG(status)) self.fireNotifiers(vtrace.NOTIFY_EXIT) elif os.WIFSTOPPED(status): sig = os.WSTOPSIG(status) self.handlePosixSignal(sig) else: print "OMG WTF JUST HAPPENED??!?11/!?1?>!"
Example #11
Source File: forking.py From ironpython2 with Apache License 2.0 | 6 votes |
def poll(self, flag=os.WNOHANG): if self.returncode is None: while True: try: pid, sts = os.waitpid(self.pid, flag) except os.error as e: if e.errno == errno.EINTR: continue # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None else: break if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) else: assert os.WIFEXITED(sts) self.returncode = os.WEXITSTATUS(sts) return self.returncode
Example #12
Source File: forkedfunc.py From py with MIT License | 6 votes |
def waitfinish(self, waiter=os.waitpid): pid, systemstatus = waiter(self.pid, 0) if systemstatus: if os.WIFSIGNALED(systemstatus): exitstatus = os.WTERMSIG(systemstatus) + 128 else: exitstatus = os.WEXITSTATUS(systemstatus) else: exitstatus = 0 signal = systemstatus & 0x7f if not exitstatus and not signal: retval = self.RETVAL.open('rb') try: retval_data = retval.read() finally: retval.close() retval = marshal.loads(retval_data) else: retval = None stdout = self.STDOUT.read() stderr = self.STDERR.read() self._removetemp() return Result(exitstatus, signal, retval, stdout, stderr)
Example #13
Source File: forking.py From oss-ftp with MIT License | 6 votes |
def poll(self, flag=os.WNOHANG): if self.returncode is None: while True: try: pid, sts = os.waitpid(self.pid, flag) except os.error as e: if e.errno == errno.EINTR: continue # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None else: break if pid == self.pid: if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) else: assert os.WIFEXITED(sts) self.returncode = os.WEXITSTATUS(sts) return self.returncode
Example #14
Source File: subprocess.py From satori with Apache License 2.0 | 5 votes |
def _handle_exitstatus(self, sts): if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) elif os.WIFEXITED(sts): self.returncode = os.WEXITSTATUS(sts) else: # Should never happen raise RuntimeError("Unknown child exit status!")
Example #15
Source File: ptyprocess.py From sublime_debugger with MIT License | 5 votes |
def wait(self): '''This waits until the child exits. This is a blocking call. This will not read any data from the child, so this will block forever if the child has unread output and has terminated. In other words, the child may have printed output then called exit(), but, the child is technically still alive until its output is read by the parent. ''' if self.isalive(): pid, status = os.waitpid(self.pid, 0) else: return self.exitstatus self.exitstatus = os.WEXITSTATUS(status) if os.WIFEXITED(status): self.status = status self.exitstatus = os.WEXITSTATUS(status) self.signalstatus = None self.terminated = True elif os.WIFSIGNALED(status): self.status = status self.exitstatus = None self.signalstatus = os.WTERMSIG(status) self.terminated = True elif os.WIFSTOPPED(status): # pragma: no cover # You can't call wait() on a child process in the stopped state. raise PtyProcessError('Called wait() on a stopped child ' + 'process. This is not supported. Is some other ' + 'process attempting job control with our child pid?') return self.exitstatus
Example #16
Source File: process.py From teleport with Apache License 2.0 | 5 votes |
def _set_returncode(self, status): if os.WIFSIGNALED(status): self.returncode = -os.WTERMSIG(status) else: assert os.WIFEXITED(status) self.returncode = os.WEXITSTATUS(status) # We've taken over wait() duty from the subprocess.Popen # object. If we don't inform it of the process's return code, # it will log a warning at destruction in python 3.6+. self.proc.returncode = self.returncode if self._exit_callback: callback = self._exit_callback self._exit_callback = None callback(self.returncode)
Example #17
Source File: utils.py From p4-utils with GNU General Public License v2.0 | 5 votes |
def run_command(command): log.debug(command) return os.WEXITSTATUS(os.system(command))
Example #18
Source File: cpuinfo.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def getoutput(cmd, successful_status=(0,), stacklevel=1): try: status, output = getstatusoutput(cmd) except EnvironmentError: e = get_exception() warnings.warn(str(e), UserWarning, stacklevel=stacklevel) return False, "" if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status: return True, output return False, output
Example #19
Source File: testutils.py From oyente with MIT License | 5 votes |
def execute_vm(bytecode_content): with open('code', 'w') as code_file: code_file.write(bytecode_content) code_file.write('\n') code_file.close() cmd = os.system('python oyente.py -b code') exit_code = os.WEXITSTATUS(cmd) if exit_code == 1: return False return True
Example #20
Source File: pexpect.py From smod-1 with GNU General Public License v2.0 | 5 votes |
def wait(self): """This waits until the child exits. This is a blocking call. This will not read any data from the child, so this will block forever if the child has unread output and has terminated. In other words, the child may have printed output then called exit(); but, technically, the child is still alive until its output is read. """ if self.isalive(): pid, status = os.waitpid(self.pid, 0) else: raise ExceptionPexpect ('Cannot wait for dead child process.') self.exitstatus = os.WEXITSTATUS(status) if os.WIFEXITED (status): self.status = status self.exitstatus = os.WEXITSTATUS(status) self.signalstatus = None self.terminated = True elif os.WIFSIGNALED (status): self.status = status self.exitstatus = None self.signalstatus = os.WTERMSIG(status) self.terminated = True elif os.WIFSTOPPED (status): raise ExceptionPexpect ('Wait was called for a child process that is stopped. This is not supported. Is some other process attempting job control with our child pid?') return self.exitstatus
Example #21
Source File: setup.py From pycopia with Apache License 2.0 | 5 votes |
def WEXITSTATUS(arg): return arg
Example #22
Source File: subprocess.py From oss-ftp with MIT License | 5 votes |
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED, _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED, _WEXITSTATUS=os.WEXITSTATUS): # This method is called (indirectly) by __del__, so it cannot # refer to anything outside of its local scope. if _WIFSIGNALED(sts): self.returncode = -_WTERMSIG(sts) elif _WIFEXITED(sts): self.returncode = _WEXITSTATUS(sts) else: # Should never happen raise RuntimeError("Unknown child exit status!")
Example #23
Source File: subprocess.py From satori with Apache License 2.0 | 5 votes |
def _on_child(self, watcher): watcher.stop() status = watcher.rstatus if os.WIFSIGNALED(status): self.returncode = -os.WTERMSIG(status) else: self.returncode = os.WEXITSTATUS(status) self.result.set(self.returncode)
Example #24
Source File: test_fdesc.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_unsetCloseOnExec(self): """ A file descriptor passed to L{fdesc._unsetCloseOnExec} is inherited by a new process image created with one of the exec family of functions. """ with open(self.mktemp(), 'wb') as fObj: fdesc._setCloseOnExec(fObj.fileno()) fdesc._unsetCloseOnExec(fObj.fileno()) status = self._execWithFileDescriptor(fObj) self.assertTrue(os.WIFEXITED(status)) self.assertEqual(os.WEXITSTATUS(status), 20)
Example #25
Source File: test_fdesc.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_setCloseOnExec(self): """ A file descriptor passed to L{fdesc._setCloseOnExec} is not inherited by a new process image created with one of the exec family of functions. """ with open(self.mktemp(), 'wb') as fObj: fdesc._setCloseOnExec(fObj.fileno()) status = self._execWithFileDescriptor(fObj) self.assertTrue(os.WIFEXITED(status)) self.assertEqual(os.WEXITSTATUS(status), 0)
Example #26
Source File: process.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def _getReason(self, status): exitCode = sig = None if os.WIFEXITED(status): exitCode = os.WEXITSTATUS(status) else: sig = os.WTERMSIG(status) if exitCode or sig: return error.ProcessTerminated(exitCode, sig, status) return error.ProcessDone(status)
Example #27
Source File: cpuinfo.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def getoutput(cmd, successful_status=(0,), stacklevel=1): try: status, output = getstatusoutput(cmd) except EnvironmentError: e = get_exception() warnings.warn(str(e), UserWarning, stacklevel=stacklevel) return False, "" if os.WIFEXITED(status) and os.WEXITSTATUS(status) in successful_status: return True, output return False, output
Example #28
Source File: _scons_subprocess.py From pivy with ISC License | 5 votes |
def _handle_exitstatus(self, sts): if os.WIFSIGNALED(sts): self.returncode = -os.WTERMSIG(sts) elif os.WIFEXITED(sts): self.returncode = os.WEXITSTATUS(sts) else: # Should never happen raise RuntimeError("Unknown child exit status!")
Example #29
Source File: fake.py From rtkbase with GNU Affero General Public License v3.0 | 5 votes |
def spawn_sub(self, program, options, background=False, prefix="", env=None): "Spawn a subprogram instance." spawncmd = None # Look for program in GPSD_HOME env variable if os.environ.get('GPSD_HOME'): for path in os.environ['GPSD_HOME'].split(':'): _spawncmd = "%s/%s" % (path, program) if os.path.isfile(_spawncmd) and os.access(_spawncmd, os.X_OK): spawncmd = _spawncmd break # if we could not find it yet try PATH env variable for it if not spawncmd: if '/usr/sbin' not in os.environ['PATH']: os.environ['PATH'] = os.environ['PATH'] + ":/usr/sbin" for path in os.environ['PATH'].split(':'): _spawncmd = "%s/%s" % (path, program) if os.path.isfile(_spawncmd) and os.access(_spawncmd, os.X_OK): spawncmd = _spawncmd break if not spawncmd: raise self.ERROR("Cannot execute %s: executable not found. " "Set GPSD_HOME env variable" % program) self.spawncmd = [spawncmd] + options.split() if prefix: self.spawncmd = prefix.split() + self.spawncmd if env: self.env = os.environ.copy() self.env.update(env) self.process = subprocess.Popen(self.spawncmd, env=self.env) if not background: self.returncode = status = self.process.wait() if os.WIFSIGNALED(status) or os.WEXITSTATUS(status): raise self.ERROR("%s exited with status %d" % (program, status))
Example #30
Source File: subprocess.py From jawfish with MIT License | 5 votes |
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED, _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED, _WEXITSTATUS=os.WEXITSTATUS): # This method is called (indirectly) by __del__, so it cannot # refer to anything outside of its local scope.""" if _WIFSIGNALED(sts): self.returncode = -_WTERMSIG(sts) elif _WIFEXITED(sts): self.returncode = _WEXITSTATUS(sts) else: # Should never happen raise RuntimeError("Unknown child exit status!")