當前位置: 首頁>>代碼示例>>Python>>正文


Python subprocess32.PIPE屬性代碼示例

本文整理匯總了Python中subprocess32.PIPE屬性的典型用法代碼示例。如果您正苦於以下問題:Python subprocess32.PIPE屬性的具體用法?Python subprocess32.PIPE怎麽用?Python subprocess32.PIPE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在subprocess32的用法示例。


在下文中一共展示了subprocess32.PIPE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: exec_command

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def exec_command(cmd, args, cwd, timeout=None):
    """
    Executes shell command inside @repo_path
    returns exec code
    """
    pipe = None
    try:
        env = os.environ
        env["PATH"] = env["NDK_TOOLCHAIN"] + "/bin:" + env["PATH"]
        pipe = Popen(args, stdin=PIPE, stdout=PIPE, cwd=cwd, env=env)
        stdout, error = pipe.communicate(timeout=timeout) if (timeout and timeout > 0) else pipe.communicate()
        logger.debug("stdout: %s", stdout)
        return pipe.returncode

    except TimeoutExpired as te:
        pipe.terminate()
        logger.error("%s timed out: %s", cmd, str(te))
        return 0

    except Exception as e:
        logger.error("%s subprocess failed: %s", cmd, str(e))
        return -1 
開發者ID:osssanitizer,項目名稱:osspolice,代碼行數:24,代碼來源:signature.py

示例2: execute

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def execute(cls, cmd, stdin_payload=None, **kwargs):
    """Execute a command via subprocess.Popen and returns the stdio.

    :param string|list cmd: A list or string representing the command to run.
    :param string stdin_payload: A string representing the stdin payload, if any, to send.
    :param **kwargs: Additional kwargs to pass through to subprocess.Popen.
    :return: A tuple of strings representing (stdout, stderr), pre-decoded for utf-8.
    :raises: `Executor.ExecutableNotFound` when the executable requested to run does not exist.
             `Executor.NonZeroExit` when the execution fails with a non-zero exit code.
    """
    process = cls.open_process(cmd=cmd,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               **kwargs)
    stdout_raw, stderr_raw = process.communicate(input=stdin_payload)
    # N.B. In cases where `stdout` or `stderr` is passed as parameters, these can be None.
    stdout = stdout_raw.decode('utf-8') if stdout_raw is not None else stdout_raw
    stderr = stderr_raw.decode('utf-8') if stderr_raw is not None else stderr_raw

    if process.returncode != 0:
      raise cls.NonZeroExit(cmd, process.returncode, stdout, stderr)

    return stdout, stderr 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:26,代碼來源:executor.py

示例3: command

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def command(cmd, *arguments, **options):

    close_fds = options.get('close_fds', True)
    cwd = options.get('cwd', None)
    shell = options.get('shell', False)
    env = options.get('env', None)
    if env is not None:
        env = dict(os.environ, **env)
    stdin = options.get('stdin', None)

    subproc = subprocess32.Popen([cmd] + list(arguments),
                                 close_fds=close_fds,
                                 shell=shell,
                                 cwd=cwd,
                                 env=env,
                                 stdin=subprocess32.PIPE,
                                 stdout=subprocess32.PIPE,
                                 stderr=subprocess32.PIPE, )

    out, err = subproc.communicate(input=stdin)

    subproc.wait()

    return (subproc.returncode, out, err) 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:26,代碼來源:proc.py

示例4: subproc

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def subproc(script, cwd=None):

    subproc = subprocess32.Popen(['sh'],
                               close_fds=True,
                               cwd=cwd,
                               stdin=subprocess32.PIPE,
                               stdout=subprocess32.PIPE,
                               stderr=subprocess32.PIPE)

    out, err = subproc.communicate(script)

    subproc.wait()

    if subproc.returncode != 0:
        print out
        print err

    return (subproc.returncode, out, err) 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:20,代碼來源:test_logutil.py

示例5: open_process

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def open_process(command, cwd=None, shell=True, _popen_lock=threading.Lock()):
    kwargs = {
        "shell": shell,
        "stdout": subprocess.PIPE,
        "stderr": subprocess.STDOUT,
        "stdin": subprocess.PIPE,
        "bufsize": 1,  # Line buffered
        "universal_newlines": True,
    }

    if cwd is not None:
        kwargs["cwd"] = cwd

    # Prevent signal propagation from parent process
    try:
        # Windows
        kwargs["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP
    except AttributeError:
        # Unix
        kwargs["preexec_fn"] = os.setpgrp

    with _popen_lock:  # Work around Python 2 Popen race condition
        return subprocess.Popen(command, **kwargs) 
開發者ID:niklasf,項目名稱:fishnet,代碼行數:25,代碼來源:fishnet.py

示例6: xvfb_supports_listen

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def xvfb_supports_listen():
    """Determine whether the '-listen' option is supported by Xvfb."""
    p = subprocess.Popen(
        ['Xvfb', '-listen', 'TCP', '-__sentinel_parameter__'],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    p.wait()
    _, stderr = p.communicate()

    match = re.search(
        br'^Unrecognized option: (?P<option>.*)$',
        stderr,
        flags=re.MULTILINE,
    ).groupdict()
    unrecognized_option = match['option']
    return unrecognized_option != b'-listen' 
開發者ID:pytest-dev,項目名稱:pytest-services,代碼行數:19,代碼來源:xvfb.py

示例7: check_output

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def check_output(*popenargs, **kwargs):
    """Run command with arguments and return its output (both stdout and stderr) as a byte string.

    If the exit code was non-zero it raises a CalledProcessWithOutputError.
    """
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')

    if 'stderr' in kwargs:
        raise ValueError('stderr argument not allowed, it will be overridden.')

    process = subprocess.Popen(
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        *popenargs, **kwargs)
    output, err = process.communicate()
    retcode = process.poll()
    if retcode:
        cmd = kwargs.get("args")
        if cmd is None:
            cmd = popenargs[0]
        raise CalledProcessWithOutputError(retcode, cmd, output, err)

    return output, err 
開發者ID:pytest-dev,項目名稱:pytest-services,代碼行數:26,代碼來源:process.py

示例8: test_stdin_stdout

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def test_stdin_stdout(self):
        proc = subprocess32.Popen(
            (sys.executable, '-m', 'pykit.p3json.tool'),
            stdin=subprocess32.PIPE, stdout=subprocess32.PIPE)
        out, err = proc.communicate(self.data.encode())
        self._assert_expected(out, linemode=True)
        self.assertEqual(err, None) 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:9,代碼來源:test_tool.py

示例9: page

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def page(lines, max_lines=10, control_char=True, pager=('less',)):

    if len(lines) > max_lines:
        pp = {'stdin': subprocess32.PIPE,
              'stdout': None,
              'stderr': None}

        cmd_pager = list(pager)
        if control_char:
            if pager == ('less', ):
                cmd_pager += ['-r']

        subproc = subprocess32.Popen(cmd_pager,
                                     close_fds=True,
                                     cwd='./',
                                     **pp)

        try:
            out, err = subproc.communicate('\n'.join(lines))
        except IOError as e:
            if e[0] == errno.EPIPE:
                pass
            else:
                raise
        subproc.wait()
    else:
        os.write(1, '\n'.join(lines) + "\n") 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:29,代碼來源:strutil.py

示例10: start

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def start(self, args):
    cmd = self._get_cmd(args)
    self.proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT, 
                                 stdout=subprocess.PIPE, preexec_fn=os.setsid,
                                 shell=self.shell)
    try:
      args = self._ready() 
      self.msg_ready(args)
    except ProcessException, e:
      # Ignore errors if process is being killed
      if not self.killing:
        self._set_error(str(e)) 
開發者ID:blissland,項目名稱:blissflixx,代碼行數:14,代碼來源:processpipe.py

示例11: __init__

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def __init__(self, args):
        self.args = args
        self.process = subprocess32.Popen(
            args,
            stdin=subprocess32.PIPE,
            stdout=subprocess32.PIPE,
            stderr=subprocess32.PIPE
        )
        self.err = None 
開發者ID:perfsonar,項目名稱:pscheduler,代碼行數:11,代碼來源:program.py

示例12: __init__

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def __init__(self, device_url, bundle_id=None):
        DeviceMixin.__init__(self)
        self.__device_url = device_url
        self.__scale = None
        
        self._wda = wda.Client(device_url)
        self._session = None
        self._bundle_id = None

        if bundle_id:
            self.start_app(bundle_id)
            
        # ioskit.Device.__init__(self, udid)

        # # xcodebuild -project  -scheme WebDriverAgentRunner -destination "id=1002c0174e481a651d71e3d9a89bd6f90d253446" test
        # # Test Case '-[UITestingUITests testRunner]' started.
        # xproj_dir = os.getenv('WEBDRIVERAGENT_DIR')
        # if not xproj_dir:
        #     raise RuntimeError("env-var WEBDRIVERAGENT_DIR need to be set")

        # proc = self._xcproc = subprocess.Popen(['/usr/bin/xcodebuild',
        #     '-project', 'WebDriverAgent.xcodeproj',
        #     '-scheme', 'WebDriverAgentRunner',
        #     '-destination', 'id='+self.udid, 'test'],
        #     stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=xproj_dir, bufsize=1, universal_newlines=True)
        # for line in iter(proc.stdout.readline, b""):
        #     print 'STDOUT:', line.strip()
        #     if 'TEST FAILED' in line:
        #         raise RuntimeError("webdriver start test failed, maybe need to unlock the keychain, try\n" + 
        #             '$ security unlock-keychain ~/Library/Keychains/login.keychain')
        #     elif "Successfully wrote Manifest cache" in line:
        #         print 'GOOD ^_^, wait 5s'
        #         time.sleep(5.0)
        #         break 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:36,代碼來源:ios_webdriveragent.py

示例13: _init_instruments

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def _init_instruments(self, bundle_id):
        self._bootstrap = os.path.join(__dir__, 'bootstrap.sh')
        self._bundle_id = bundle_id
        self._env.update({'UDID': self.udid, 'BUNDLE_ID': self._bundle_id})
        # 1. remove pipe
        # subprocess.check_output([self._bootstrap, 'reset'], env=self._env)
        # 2. start instruments
        self._proc = subprocess.Popen([self._bootstrap, 'instruments'], env=self._env, stdout=subprocess.PIPE)
        self.sleep(5.0)
        self._wait_instruments() 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:12,代碼來源:__init__.py

示例14: raw_cmd

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def raw_cmd(self, *args, **kwargs):
        '''adb command. return the subprocess.Popen object.'''
        cmds = [self.adb_path()] + self._host_port_args + list(args)
        kwargs['stdout'] = kwargs.get('stdout', subprocess.PIPE)
        kwargs['stderr'] = kwargs.get('stderr', subprocess.PIPE)
        # if os.name != "nt":
        #     cmd_line = [" ".join(cmd_line)]
        cmds = [strutils.decode(v) for v in cmds]
        return subprocess.Popen(cmds, **kwargs) 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:11,代碼來源:client.py

示例15: start_app

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import PIPE [as 別名]
def start_app(self, bundle_id):
        '''
        Start app by bundle_id
        Args:
            - bundle_id(string): ex com.netease.my
        Returns:
            idevicedebug subprocess instance
        '''
        idevicedebug = must_look_exec('idevicedebug')

        # run in background
        kwargs = {'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE}
        if sys.platform != 'darwin':
            kwargs['close_fds'] = True
        return subprocess.Popen([idevicedebug, "--udid", self.udid, 'run', bundle_id], **kwargs) 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:17,代碼來源:ioskit.py


注:本文中的subprocess32.PIPE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。