当前位置: 首页>>代码示例>>Python>>正文


Python subprocess32.Popen类代码示例

本文整理汇总了Python中subprocess32.Popen的典型用法代码示例。如果您正苦于以下问题:Python Popen类的具体用法?Python Popen怎么用?Python Popen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Popen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_playbook

def run_playbook(playbook, inventory, *args, **kwargs):
    env = ansible_env(os.environ.copy())
    cmd = ['ansible-playbook', '-i', inventory, playbook] + list(args)

    if verbosity():
        cmd += ['-' + ('v' * verbosity())]

    show_timestamp = False
    if 'timestamp' in kwargs:
        show_timestamp = kwargs['timestamp']
        del kwargs['timestamp']

    output = print
    if show_timestamp:
        output = timestamp

    logger.info('running %s', ' '.join(cmd))
    logger.debug('env: %r', env)

    process = Popen(cmd, env=env, stdout=PIPE,
                    bufsize=1, **kwargs)
    for line in iter(process.stdout.readline, b''):
        output(line[:-1])
    # empty output buffers
    process.poll()
    return process.returncode
开发者ID:AerisCloud,项目名称:AerisCloud,代码行数:26,代码来源:ansible.py

示例2: install_dropbox_helper

def install_dropbox_helper(package = None, fullpath = None, tmp = False):
    if not os.path.exists(HELPER_INSTALLER_PATH):
        raise InstallError('no installer')
    assert package or fullpath
    if not fullpath:
        fullpath = get_package_location(package)
    TRACE('Installing %s', package or fullpath)
    cmd = 'install-tmp' if tmp else 'install'
    p = Popen([HELPER_INSTALLER_PATH,
     cmd,
     BUILD_KEY,
     fullpath], stdout=PIPE, stderr=PIPE)
    out, err = p.communicate()
    if p.returncode != 0:
        if out:
            TRACE('stdout: %s', out)
        if err:
            TRACE('stderr: %s', err)
        raise InstallError('Installer returned %d' % p.returncode)
    if tmp:
        path = None
        for l in out.split('\n'):
            m = re.match('\\<path\\>(?P<path>.+)\\</path\\>', l)
            if m:
                path = m.group('path')

        if path:
            return os.path.join(path, REL_HELPERS_DIR)
        raise InstallError('no path')
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:29,代码来源:helper_installer.py

示例3: run

def run():
    is_timeout = False
    code = request.form.get('code')
    stdin = request.form.get('stdin')
    code_filename = "/tmp/" + str(uuid4())
    try:
        with open(code_filename, "w") as code_file:
            code_file.write(code)
        p = Popen(
            ['bbm', code_filename],
            stdout=PIPE,
            stdin=PIPE,
            stderr=PIPE
        )
        stdout, stderr = p.communicate(input=stdin.encode('utf-8'), timeout=15)
    except TimeoutExpired:
        is_timeout = True
        p.kill()
        stdout, stderr = p.communicate()
    finally:
        remove(code_filename)
    stdout = stdout.decode('utf-8')
    stderr = stderr.decode('utf-8')
    return jsonify({
        'stdout': stdout,
        'stderr': stderr,
        'is_timeout': is_timeout
    })
开发者ID:bibim-lang,项目名称:pybibim-web-demo,代码行数:28,代码来源:__init__.py

示例4: process

    def process(self, json_data, namedblobfile=None):

        tmpdir_path = tempfile.mkdtemp(prefix='opengever.core.sablon_')
        output_path = join(tmpdir_path, 'sablon_output.docx')

        if namedblobfile is None:
            template_path = self.template.as_file(tmpdir_path)
        else:
            template_path = join(tmpdir_path, namedblobfile.filename)
            with open(template_path, 'wb') as template_file:
                template_file.write(namedblobfile.data)

        try:
            sablon_path = environ.get('SABLON_BIN', 'sablon')
            subprocess = Popen(
                [sablon_path, template_path, output_path],
                stdin=PIPE, stdout=PIPE, stderr=PIPE)
            self.stdout, self.stderr = subprocess.communicate(input=json_data)
            self.returncode = subprocess.returncode
            if not self.is_processed_successfully():
                raise SablonProcessingFailed(self.stderr)
            with open(output_path, 'rb') as outfile:
                self.file_data = outfile.read()
        finally:
            shutil.rmtree(tmpdir_path)

        return self
开发者ID:4teamwork,项目名称:opengever.core,代码行数:27,代码来源:sablon.py

示例5: run_judge_client

 def run_judge_client(self):
     self.copy_assets()
     args = ["python", os.path.realpath('judge-client.py'), './attacker', './defender']
     self.log += ['Running: ' + ' '.join(args)]
     proc = Popen(args, cwd=self.base_dir, stdin=PIPE, stdout=PIPE, stderr=PIPE)
     output = proc.communicate()
     self.log += [str(output[1])]
     if proc.returncode:
         self.log += ["Judge client crashed with return code %d." % proc.returncode]
         raise JudgeClientException("judge client crashed.")
     result = output[0].split('\n')
     winner = result[0]
     if winner == "attacker":
         self.record.attacker_wins()
     elif winner == "defender":
         self.record.defender_wins()
     else:
         self.log += ["Judge client return unknown winner %s." % winner]
         raise JudgeClientException("unknown winner.")
     reason = result[1]
     if reason == "Finished":
         self.record.status = ExecutionRecord.STATUS_FINISHED
     elif reason == "IllegalMovement":
         self.record.status = ExecutionRecord.STATUS_ILLEGAL_MOVE
     elif reason == "IllegalOutput":
         self.record.status = ExecutionRecord.STATUS_BAD_FORMAT
     elif reason == "TLE":
         self.record.status = ExecutionRecord.STATUS_TLE
     elif reason == "Crashed":
         self.record.status = ExecutionRecord.STATUS_RUNTIME_ERROR
     else:
         self.log += ["Judge client return unknown reason %s." % reason]
         raise JudgeClientException("unknown reason.")
     self.record.replay = result[2:]
开发者ID:ruc-acm,项目名称:online-vs-platform,代码行数:34,代码来源:judge-daemon.py

示例6: check_container_status_rkt

def check_container_status_rkt():
    """
    Checks and prints the calico/node container status when running in rkt.
    """
    list_cmd = ["sudo", "rkt", "list"]
    p = Popen(list_cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    stdout, stderr = p.communicate()
    containers = RKT_CONTAINER_RE.findall(stdout)

    if p.returncode:
        print "Unable to list rkt containers: '%s'" % stderr.strip()
        sys.exit(1)

    if len(containers) == 0:
        print "calico-node container not running"
        sys.exit(1)
    else:
        # Get statuses for all calico/node containers, and determine
        # if any are running.
        statuses = [c[2] for c in containers]
        running = "running" in statuses

        # If one is running, status is "running".  Else, use the status of
        # the first container.
        status = "running" if running else statuses[0]

        # Print status.  If it at least one is running, this will display
        # "running" status.
        print "calico-node container status: %s" % status
开发者ID:alexbrand,项目名称:calico-containers,代码行数:29,代码来源:status.py

示例7: invoke_side_effects

def invoke_side_effects(argv):
    log("invoke_side_effects: %s"
        % ' '.join(sys.argv))

    gccinv = GccInvocation(argv)

    # Try to run each side effect in a subprocess, passing in a path
    # for the XML results to be written to.
    # Cover a multitude of possible failures by detecting if no output
    # was written, and capturing *that* as a failure
    for sourcefile in gccinv.sources:
        if sourcefile.endswith('.c'): # FIXME: other extensions?
            for script, genname in [('invoke-cppcheck', 'cppcheck'),
                                    ('invoke-clang-analyzer', 'clang-analyzer'),
                                    ('invoke-cpychecker', 'cpychecker'),

                                    # Uncomment the following to test a
                                    # checker that fails to write any XML:
                                    # ('echo', 'failing-checker'),

                                    ]:
                with tempfile.NamedTemporaryFile() as f:
                    dstxmlpath = f.name
                assert not os.path.exists(dstxmlpath)

                # Restrict the invocation to just one source file at a
                # time:
                singleinv = gccinv.restrict_to_one_source(sourcefile)
                singleargv = singleinv.argv

                TIMEOUT=60
                t = Timer()

                args = [script, dstxmlpath] + singleargv
                log('invoking args: %r' % args)
                p = Popen(args,
                          stdout=PIPE, stderr=PIPE)
                try:
                    out, err = p.communicate(timeout=TIMEOUT)
                    write_streams(script, out, err)

                    if os.path.exists(dstxmlpath):
                        with open(dstxmlpath) as f:
                            analysis = Analysis.from_xml(f)
                    else:
                        analysis = make_failed_analysis(genname, sourcefile, t,
                                                        msgtext=('Unable to locate XML output from %s'
                                                                 % script),
                                                        failureid='no-output-found')
                        analysis.set_custom_field('stdout', out)
                        analysis.set_custom_field('stderr', err)
                        analysis.set_custom_field('returncode', p.returncode)
                except TimeoutExpired:
                    analysis = make_failed_analysis(genname, sourcefile, t,
                                                    msgtext='Timeout running %s' % genname,
                                                    failureid='timeout')
                    analysis.set_custom_field('timeout', TIMEOUT)
                analysis.set_custom_field('gcc-invocation', ' '.join(argv))
                write_analysis_as_xml(analysis)
开发者ID:pombredanne,项目名称:mock-with-analysis,代码行数:59,代码来源:fakegcc.py

示例8: run

def run(pro, *args, **kwargs):
    """
    Run vagrant within a project
    :param pro: .project.Project
    :param args: list[string]
    :param kwargs: dict[string,string]
    :return:
    """
    with cd(pro.folder()):
        # fix invalid exports for vagrant
        NFS().fix_anomalies()

        new_env = ansible_env(os.environ.copy())

        new_env['PATH'] = os.pathsep.join([
            new_env['PATH'],
            os.path.join(aeriscloud_path, 'venv/bin')
        ])
        new_env['VAGRANT_DOTFILE_PATH'] = pro.vagrant_dir()
        new_env['VAGRANT_CWD'] = pro.vagrant_working_dir()
        new_env['VAGRANT_DISKS_PATH'] = os.path.join(data_dir(), 'disks')

        # We might want to remove that or bump the verbosity level even more
        if verbosity() >= 4:
            new_env['VAGRANT_LOG'] = 'info'

        new_env['AERISCLOUD_PATH'] = aeriscloud_path
        new_env['AERISCLOUD_ORGANIZATIONS_DIR'] = os.path.join(data_dir(),
                                                               'organizations')

        org = default_organization()
        if org:
            new_env['AERISCLOUD_DEFAULT_ORGANIZATION'] = org

        organization_name = pro.organization()
        if organization_name:
            organization = Organization(organization_name)
        else:
            organization = Organization(org)

        basebox_url = organization.basebox_url()
        if basebox_url:
            new_env['VAGRANT_SERVER_URL'] = basebox_url

        args = ['vagrant'] + list(args)
        logger.debug('running: %s\nenv: %r', ' '.join(args), new_env)

        # support for the vagrant prompt
        if args[1] == 'destroy':
            return call(args, env=new_env, **kwargs)
        else:
            process = Popen(args, env=new_env, stdout=PIPE,
                            bufsize=1, **kwargs)
            for line in iter(process.stdout.readline, b''):
                timestamp(line[:-1])
            # empty output buffers
            process.poll()
            return process.returncode
开发者ID:AerisCloud,项目名称:AerisCloud,代码行数:58,代码来源:vagrant.py

示例9: terminate

 def terminate(self):
     """Terminates the process"""
     # Don't terminate a process that we know has already died.
     if self.returncode is not None:
         return
     if self._job:
         winprocess.TerminateJobObject(self._job, 127)
         self.returncode = 127
     else:
         Popen.terminate(self)
开发者ID:SublimeCodeIntel,项目名称:codeintel,代码行数:10,代码来源:process.py

示例10: run

 def run(self):
     '''
     Execute a module as a bash command. Open handles file object as input.
     Log output and/or errors.
     '''
     command = self.bake_command()
     try:
         process = Popen(command,
                         stdin=self.streams['input'],
                         stdout=self.streams['output'],
                         stderr=self.streams['error'])
         # Prepare handles input.
         input_data = None
         if self.streams['input'] == PIPE:
             input_data = open(self.handles).readlines()
             # We have to provide the temporary filename to the modules.
             i = -1
             for line in input_data:
                 i = i + 1
                 # Replace the value of the 'hdf5_filename' key.
                 # Doing this via YAML should be saver.
                 if re.match('hdf5_filename', line):
                     hdf5_key = yaml.load(line)
                     hdf5_key['hdf5_filename'] = self.tmp_filename
                     input_data[i] = yaml.dump(hdf5_key,
                                               default_flow_style=False)
             # Create the new handles string.
             input_data = ''.join(input_data)
         # Execute sub-process.
         (stdoutdata, stderrdata) = process.communicate(input=input_data)
         # Write output and errors if 'logging' is requested by user
         if self.logging_level is not None:
             self.write_output_and_errors(stdoutdata, stderrdata)
         # Modify for nicer output to command line.
         ignore_list = ['INFO:']
         if any([re.search(x, stderrdata) for x in ignore_list]):
             newstderrdata = str()
             for line in stderrdata.split('\n'):
                 if not any([re.search(x, line) for x in ignore_list]):
                     newstderrdata = newstderrdata + line
             stderrdata = newstderrdata
         print stdoutdata
         print stderrdata
         # Close STDIN file descriptor.
         process.stdin.close
         # Take care of any errors during the execution.
         if process.returncode > 0 or re.search('Error', stderrdata):
             raise JteratorError(self.get_error_message(process,
                                 input_data, stdoutdata, stderrdata))
     except ValueError as error:
         raise JteratorError('Failed running \'%s\'. Reason: \'%s\'' %
                             (command, str(error)))
开发者ID:brainy-minds,项目名称:Jterator,代码行数:52,代码来源:module.py

示例11: invoke_real_executable

def invoke_real_executable(argv):
    args = [get_real_executable(argv)] + argv[1:]
    if 0:
        log(' '.join(args))
    p = Popen(args, stderr=PIPE)
    try:
        t = Timer()
        out, err = p.communicate()
        sys.stderr.write(err)
        parse_gcc_stderr(err,
                         stats=make_stats(t))
    except KeyboardInterrupt:
        pass
    return p.returncode
开发者ID:pombredanne,项目名称:mock-with-analysis,代码行数:14,代码来源:fakegcc.py

示例12: handle_eval

    def handle_eval(self, record):
        self.process = Popen(['./sumfun_ext', array2str(record.params[0])],
                             stdout=PIPE)

        val = np.nan
        # Continuously check for new outputs from the subprocess
        while True:
            output = self.process.stdout.readline()
            if output == '' and self.process.poll() is not None:  # No new output
                break
            if output:  # New intermediate output
                try:
                    val = float(output.strip())  # Try to parse output
                    if val > 350:  # Terminate if too large
                        self.process.terminate()
                        self.finish_success(record, 350)
                        return
                except ValueError:  # If the output is nonsense we terminate
                    logging.warning("Incorrect output")
                    self.process.terminate()
                    self.finish_failure(record)
                    return

        rc = self.process.poll()  # Check the return code
        if rc < 0 or np.isnan(val):
            logging.warning("Incorrect output or crashed evaluation")
            self.finish_failure(record)
        else:
            self.finish_success(record, val)
开发者ID:NoobSajbot,项目名称:pySOT,代码行数:29,代码来源:test_subprocess_partial_info.py

示例13: run

    def run(self, *args, **kwargs):
        if self.path is not None:
            # only None when called in the __init__ function
            kwargs.setdefault("cwd", self.path)

        # NOTE if we do want to make a copy of environmental variables,
        # we must remove GIT_WORK_TREE
        kwargs["env"] = {}
        kwargs["stdout"] = PIPE
        kwargs["stderr"] = PIPE

        proc = Popen(args, **kwargs)
        (stdout, stderr) = proc.communicate()
        if proc.returncode != 0:
            raise CommandError(args[0], proc.returncode, stdout, stderr)
        return stdout
开发者ID:naphatkrit,项目名称:easyci,代码行数:16,代码来源:base.py

示例14: DummySim

class DummySim(ProcessWorkerThread):

    def handle_eval(self, record):
        # This gives a file name / directory name that no other thread can use
        my_unique_filename = my_gen.next_filename()
        my_unique_filename = str(my_unique_filename) + ".txt"

        # Print to the input file
        f = open(my_unique_filename, 'w')
        f.write(array2str(record.params[0]))
        f.close()

        # Run the objective function and pass the filename of the input file
        self.process = Popen(['./sphere_ext_files', my_unique_filename], stdout=PIPE)
        out = self.process.communicate()[0]

        # Parse the output
        try:
            val = float(out)  # This raises ValueError if out is not a float
            self.finish_success(record, val)
            os.remove(my_unique_filename)  # Remove input file
        except ValueError:
            logging.warning("Function evaluation crashed/failed")
            self.finish_failure(record)
            os.remove(my_unique_filename)  # Remove input file
开发者ID:NoobSajbot,项目名称:pySOT,代码行数:25,代码来源:test_subprocess_files.py

示例15: run_compiler

 def run_compiler(self, language, filename, executable_name):
     args = ["g++" if language else "gcc", "-static", "-w", "-O2", filename, "-o",
             executable_name]
     self.log += ['Running: ' + ' '.join(args)]
     proc = Popen(args,
                  cwd=self.base_dir, stdin=PIPE, stdout=PIPE, stderr=PIPE)
     output = proc.communicate(timeout=self.COMPILE_TIMEOUT)
     self.log += [str(output[1])]
     if proc.poll() is None:
         try:
             self.log += ['Compile timeout.']
             proc.kill()
         except Exception:
             pass
     self.log += ["Compiler returns %d." % proc.returncode]
     if proc.returncode:
         raise CompileErrorException()
开发者ID:ruc-acm,项目名称:online-vs-platform,代码行数:17,代码来源:judge-daemon.py


注:本文中的subprocess32.Popen类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。