• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python subprocess._cleanup函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: do_task

def do_task(**post_data):
    callback = post_data.get('callback_url')
    acceptkey = post_data.get('accept_key')
    task_id = post_data.get('task_id')
    playbook = post_data.get('playbook')
    extra_vars = post_data.get('extra_vars')
    hosts = post_data.get('hosts')
    p = Popen(
        "/usr/bin/ansible-playbook -i %s  %s --extra-vars='%s' -s" %
        (hosts, playbook, extra_vars),
        shell=True,
        stdout=PIPE,
        stderr=PIPE)
    try:
        stdout, stderr = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode

    log_debug(
        'task id  %d in hosts %s playbook %s return stdout %s ,stderr %s!' %
        (task_id, hosts, playbook, stdout, stderr))
    return {
        'task_id': task_id,
        'callback_url': callback,
        'accept_key': acceptkey,
        'hosts': hosts,
        'playbook': playbook,
        'stdout': stdout,
        'stderr': stderr,
        'returncode': rc
    }
开发者ID:xiaomatech,项目名称:ops,代码行数:34,代码来源:common.py


示例2: process

    def process(self, the_queue):
        if self.threads < 2:
            worker(self, the_queue)
        else:
            if sys.version_info < (2, 6):
                # work around a race condition in subprocess
                _old_subprocess_cleanup = subprocess._cleanup

                def _cleanup():
                    pass

                subprocess._cleanup = _cleanup

            threads = []

            for i in range(self.threads):
                thread = threading.Thread(target=worker, args=(self, the_queue))
                thread.start()
                threads.append(thread)
            for thread in threads:
                thread.join()
            if sys.version_info < (2, 6):
                subprocess._cleanup = _old_subprocess_cleanup
                subprocess._cleanup()

        if self.errors:
            logger.error("There have been errors, see messages above.")
            sys.exit(1)
开发者ID:angelnan,项目名称:mr.developer,代码行数:28,代码来源:common.py


示例3: run_python_until_end

def run_python_until_end(*args, **env_vars):
    env_required = _interpreter_requires_environment()
    if '__isolated' in env_vars:
        isolated = env_vars.pop('__isolated')
    else:
        isolated = not env_vars and not env_required
    cmd_line = [sys.executable, '-X', 'faulthandler']
    if isolated:
        # isolated mode: ignore Python environment variables, ignore user
        # site-packages, and don't add the current directory to sys.path
        cmd_line.append('-I')
    elif not env_vars and not env_required:
        # ignore Python environment variables
        cmd_line.append('-E')
    # Need to preserve the original environment, for in-place testing of
    # shared library builds.
    env = os.environ.copy()
    # But a special flag that can be set to override -- in this case, the
    # caller is responsible to pass the full environment.
    if env_vars.pop('__cleanenv', None):
        env = {}
    env.update(env_vars)
    cmd_line.extend(args)
    p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                         env=env)
    try:
        out, err = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode
    err = strip_python_stderr(err)
    return _PythonRunResult(rc, out, err), cmd_line
开发者ID:dougmassay,项目名称:cpython3.4.4,代码行数:35,代码来源:script_helper.py


示例4: run

    def run(self):
        currentDir = os.getcwd()

        try:
            os.chdir(self.pathToFXApp)
            process = subprocess.Popen([shlex.split(self.cmdFXAPP), self.cmdFXArg], shell=True, stdout=subprocess.PIPE)
            self.lgr.info('Exteral application started')
        except Exception as e:
            self.lgr.error('Critical: Cannot execute fluid explorer app. Details: %s', e.message)
            self.emit(QtCore.SIGNAL('update(QString)'), "ERROR")
            return

        finally:
            os.chdir(currentDir)
            subprocess._cleanup()

        while self.running:

            output = process.stdout.readline()
            if output.startswith(self.SEARCH_PATTERN_CMD):
                self.lgr.info('Received event from fluid explorer app')

            if output == '' and process.poll() is not None:
                break
            if output:
                self.lgr.info(output.strip())
                #print output.strip()

        rc = process.poll()
        return rc
开发者ID:wolfpatrick,项目名称:FluidExplorerPlugin,代码行数:30,代码来源:ExternalCallWorkerThread.py


示例5: _assert_python

def _assert_python(expected_success, *args, **env_vars):
    cmd_line = [sys.executable]
    if not env_vars:
        cmd_line.append('-E')
    cmd_line.extend(args)
    # Need to preserve the original environment, for in-place testing of
    # shared library builds.
    env = os.environ.copy()
    env.update(env_vars)
    p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                         env=env)
    try:
        out, err = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode
    err =  strip_python_stderr(err)
    if (rc and expected_success) or (not rc and not expected_success):
        raise AssertionError(
            "Process return code is %d, "
            "stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
    return rc, out, err
开发者ID:Stewori,项目名称:jython,代码行数:25,代码来源:script_helper.py


示例6: gen

def gen(project_name, database_host, database_user,database,database_passwd='',table='',database_port=3306):
    #gen config
    with open('configs/db.py','wb+') as f:
        f.write("db={ 'host':"+database_host+
                ',port:'+database_port+
                ',user:'+database_user+
                ',password:'+database_passwd+
                ',database:'+database+
                "}")

    #gen model
    p = subprocess.Popen('python -m pwiz -e mysql -u%s -H%s -P%s -p%d %s -t %s >./models/%s.py'%
                     (database_user,database_host,database_passwd,database_port,database,table,database+table),
                     shell=True,stderr=subprocess.PIPE,stdout=subprocess.PIPE)

    try:
        stdout,stderr = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode
    
    if rc !=0 :
        print "gen model error %s" % stderr
        sys.exit(1)
    #gen template

    #gen controller

    #copy
    for item in dirs:
        shutil.copy(item, os.path.join(project_name, item))
开发者ID:xianhuawei,项目名称:utils,代码行数:33,代码来源:app.py


示例7: do_task

def do_task(**post_data):
    callback = post_data.get("callback_url", callback_url)
    acceptkey = post_data.get("accept_key", accept_key)
    task_id = post_data.get("task_id", 0)
    playbook = post_data.get("playbook", "")
    extra_vars = post_data.get("extra_vars", "")
    hosts = post_data.get("hosts", "127.0.0.1,")
    p = Popen(
        "/usr/bin/ansible-playbook -i %s  %s --extra-vars='%s' -s" % (hosts, playbook, extra_vars),
        shell=True,
        stdout=PIPE,
        stderr=PIPE,
    )
    try:
        stdout, stderr = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode

    mylggr.debug(
        "task id  %d in hosts %s playbook %s return stdout %s ,stderr %s!" % (task_id, hosts, playbook, stdout, stderr)
    )
    return {
        "task_id": task_id,
        "callback_url": callback,
        "accept_key": acceptkey,
        "hosts": hosts,
        "playbook": playbook,
        "stdout": stdout,
        "stderr": stderr,
        "returncode": rc,
    }
开发者ID:xianhuawei,项目名称:utils,代码行数:34,代码来源:web_task.py


示例8: _assert_python

def _assert_python(expected_success, *args, **env_vars):
    env_required = interpreter_requires_environment()
    if '__isolated' in env_vars:
        isolated = env_vars.pop('__isolated')
    else:
        isolated = not env_vars and not env_required
    cmd_line = [sys.executable, '-X', 'faulthandler']
    if isolated:
        # isolated mode: ignore Python environment variables, ignore user
        # site-packages, and don't add the current directory to sys.path
        cmd_line.append('-I')
    elif not env_vars and not env_required:
        # ignore Python environment variables
        cmd_line.append('-E')
    # Need to preserve the original environment, for in-place testing of
    # shared library builds.
    env = os.environ.copy()
    # But a special flag that can be set to override -- in this case, the
    # caller is responsible to pass the full environment.
    if env_vars.pop('__cleanenv', None):
        env = {}
    env.update(env_vars)
    cmd_line.extend(args)
    p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                         env=env)
    try:
        out, err = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode
    err = strip_python_stderr(err)
    if (rc and expected_success) or (not rc and not expected_success):
        # Limit to 80 lines to ASCII characters
        maxlen = 80 * 100
        if len(out) > maxlen:
            out = b'(... truncated stdout ...)' + out[-maxlen:]
        if len(err) > maxlen:
            err = b'(... truncated stderr ...)' + err[-maxlen:]
        out = out.decode('ascii', 'replace').rstrip()
        err = err.decode('ascii', 'replace').rstrip()
        raise AssertionError("Process return code is %d\n"
                             "command line: %r\n"
                             "\n"
                             "stdout:\n"
                             "---\n"
                             "%s\n"
                             "---\n"
                             "\n"
                             "stderr:\n"
                             "---\n"
                             "%s\n"
                             "---"
                             % (rc, cmd_line,
                                out,
                                err))
    return rc, out, err
开发者ID:Cartmanfku,项目名称:cpython,代码行数:59,代码来源:script_helper.py


示例9: _kill_python

def _kill_python(p):
    p.stdin.close()
    data = p.stdout.read()
    p.stdout.close()
    # try to cleanup the child so we don't appear to leak when running
    # with regrtest -R.  This should be a no-op on Windows.
    subprocess._cleanup()
    return data
开发者ID:Cinnz,项目名称:python,代码行数:8,代码来源:test_cmd_line.py


示例10: kill_python

def kill_python(p):
    """Run the given Popen process until completion and return stdout."""
    p.stdin.close()
    data = p.stdout.read()
    p.stdout.close()
    # try to cleanup the child so we don't appear to leak when running
    # with regrtest -R.
    p.wait()
    subprocess._cleanup()
    return data
开发者ID:dougmassay,项目名称:cpython3.4.4,代码行数:10,代码来源:script_helper.py


示例11: tearDown

 def tearDown(self):
     for inst in popen2._active:
         inst.wait()
     popen2._cleanup()
     self.assertFalse(popen2._active, "popen2._active not empty")
     # The os.popen*() API delegates to the subprocess module (on Unix)
     import subprocess
     for inst in subprocess._active:
         inst.wait()
     subprocess._cleanup()
     self.assertFalse(subprocess._active, "subprocess._active not empty")
     reap_children()
开发者ID:clamxyz,项目名称:LearnPythonTheHardWay,代码行数:12,代码来源:test_popen2.py


示例12: tearDown

 def tearDown(self):
     for inst in popen2._active:
         inst.wait()
     popen2._cleanup()
     self.assertFalse(popen2._active, "popen2._active not empty")
     # The os.popen*() API delegates to the subprocess module (on Unix)
     if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/15512"):
         import subprocess
         for inst in subprocess._active:
             inst.wait()
         subprocess._cleanup()
         self.assertFalse(subprocess._active, "subprocess._active not empty")
     reap_children()
开发者ID:BillyboyD,项目名称:main,代码行数:13,代码来源:test_popen2.py


示例13: run_python_until_end

def run_python_until_end(*args, **env_vars):
    env_required = interpreter_requires_environment()
    cwd = env_vars.pop('__cwd', None)
    if '__isolated' in env_vars:
        isolated = env_vars.pop('__isolated')
    else:
        isolated = not env_vars and not env_required
    cmd_line = [sys.executable, '-X', 'faulthandler']
    if isolated:
        # isolated mode: ignore Python environment variables, ignore user
        # site-packages, and don't add the current directory to sys.path
        cmd_line.append('-I')
    elif not env_vars and not env_required:
        # ignore Python environment variables
        cmd_line.append('-E')

    # But a special flag that can be set to override -- in this case, the
    # caller is responsible to pass the full environment.
    if env_vars.pop('__cleanenv', None):
        env = {}
        if sys.platform == 'win32':
            # Windows requires at least the SYSTEMROOT environment variable to
            # start Python.
            env['SYSTEMROOT'] = os.environ['SYSTEMROOT']

        # Other interesting environment variables, not copied currently:
        # COMSPEC, HOME, PATH, TEMP, TMPDIR, TMP.
    else:
        # Need to preserve the original environment, for in-place testing of
        # shared library builds.
        env = os.environ.copy()

    # set TERM='' unless the TERM environment variable is passed explicitly
    # see issues #11390 and #18300
    if 'TERM' not in env_vars:
        env['TERM'] = ''

    env.update(env_vars)
    cmd_line.extend(args)
    proc = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                         env=env, cwd=cwd)
    with proc:
        try:
            out, err = proc.communicate()
        finally:
            proc.kill()
            subprocess._cleanup()
    rc = proc.returncode
    err = strip_python_stderr(err)
    return _PythonRunResult(rc, out, err), cmd_line
开发者ID:Eyepea,项目名称:cpython,代码行数:51,代码来源:script_helper.py


示例14: exit_sequence

def exit_sequence(comms_port):
    if process_result(make_request(url_prefix+url_shutdown(activity_id['processor']))) == 'success':
        print "Shutting down waypoint processor activity"
        time.sleep(0.5)
        if process_result(make_request(url_prefix+url_shutdown(activity_id['captain']))) == 'success':
            print "Shutting down captain activity"
            time.sleep(10)
            if process_result(make_request(url_prefix+url_shutdown(activity_id['generator']))) == 'success':
                print "Shutting down waypoint generator activity"
                time.sleep(0.5)
                if process_result(make_request(url_prefix+url_shutdown(activity_id[comms_port]))) == 'success':
                    print "Shutting down communications activity"
                    time.sleep(1)
                    if process_result(make_request(url_prefix+url_shutdown(activity_id['mavlink']))) == 'success':
                        print "Shutting down mavlink activity"
                        time.sleep(2)
                        subprocess._cleanup()
                        print "Everything shut down"
                        return
    print "Could not shutdown all the activities"
开发者ID:aksonuabhay,项目名称:IS-Erle,代码行数:20,代码来源:start.py


示例15: _assert_python

def _assert_python(expected_success, *args, **env_vars):
    env_required = _interpreter_requires_environment()
    if '__isolated' in env_vars:
        isolated = env_vars.pop('__isolated')
    else:
        isolated = not env_vars and not env_required
    cmd_line = [sys.executable, '-X', 'faulthandler']
    if isolated:
        # isolated mode: ignore Python environment variables, ignore user
        # site-packages, and don't add the current directory to sys.path
        cmd_line.append('-I')
    elif not env_vars and not env_required:
        # ignore Python environment variables
        cmd_line.append('-E')
    # Need to preserve the original environment, for in-place testing of
    # shared library builds.
    env = os.environ.copy()
    # But a special flag that can be set to override -- in this case, the
    # caller is responsible to pass the full environment.
    if env_vars.pop('__cleanenv', None):
        env = {}
    env.update(env_vars)
    cmd_line.extend(args)
    p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                         env=env)
    try:
        out, err = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode
    err = strip_python_stderr(err)
    if (rc and expected_success) or (not rc and not expected_success):
        raise AssertionError(
            "Process return code is %d, command line was: %r, "
            "stderr follows:\n%s" % (rc, cmd_line,
                                     err.decode('ascii', 'ignore')))
    return rc, out, err
开发者ID:SantoKo,项目名称:RPI3-Desktop,代码行数:40,代码来源:script_helper.py


示例16: do_task

def do_task(**post_data):
    callback = post_data.get('callback_url', callback_url)
    acceptkey = post_data.get('accept_key', accept_key)
    task_id = post_data.get('task_id', 0)
    filepath = post_data.get('upfile').replace('\\','/')
    filename = filepath.split('/')[-1]

    newFile = os.path.join(uploadpath, filename)

    if not os.path.exists(uploadpath):
        os.mkdir(uploadpath)

    fout = open(newFile,'w')
    fout.write(post_data.get('filename'))
    fout.close()

    #创建yum仓库索引
    p = subprocess.Popen("cd %s && createrepo %s" % (rpmdir,yumname),
                     shell=True,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.PIPE)
    try:
        stdout, stderr = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode

    mylggr.debug(
        'task id  %d return stdout %s ,stderr %s!' %
        (task_id, stdout, stderr))
    return {'task_id': task_id,
            'callback_url': callback,
            'accept_key': acceptkey,
            'filename': filename,
            'stdout': stdout,
            'stderr': stderr,
            'returncode': rc}
开发者ID:xianhuawei,项目名称:utils,代码行数:39,代码来源:upload.py


示例17: run_python_until_end

def run_python_until_end(*args, **env_vars):
    env_required = interpreter_requires_environment()
    if "__isolated" in env_vars:
        isolated = env_vars.pop("__isolated")
    else:
        isolated = not env_vars and not env_required
    cmd_line = [sys.executable, "-X", "faulthandler"]
    if isolated:
        # isolated mode: ignore Python environment variables, ignore user
        # site-packages, and don't add the current directory to sys.path
        cmd_line.append("-I")
    elif not env_vars and not env_required:
        # ignore Python environment variables
        cmd_line.append("-E")
    # Need to preserve the original environment, for in-place testing of
    # shared library builds.
    env = os.environ.copy()
    # set TERM='' unless the TERM environment variable is passed explicitly
    # see issues #11390 and #18300
    if "TERM" not in env_vars:
        env["TERM"] = ""
    # But a special flag that can be set to override -- in this case, the
    # caller is responsible to pass the full environment.
    if env_vars.pop("__cleanenv", None):
        env = {}
    env.update(env_vars)
    cmd_line.extend(args)
    p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
    try:
        out, err = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode
    err = strip_python_stderr(err)
    return _PythonRunResult(rc, out, err), cmd_line
开发者ID:abalkin,项目名称:cpython,代码行数:37,代码来源:script_helper.py


示例18: _assert_python

def _assert_python(expected_success, *args, **env_vars):
    if "__isolated" in env_vars:
        isolated = env_vars.pop("__isolated")
    else:
        isolated = not env_vars
    cmd_line = [sys.executable]
    if sys.version_info >= (3, 3):
        cmd_line.extend(("-X", "faulthandler"))
    if isolated and sys.version_info >= (3, 4):
        # isolated mode: ignore Python environment variables, ignore user
        # site-packages, and don't add the current directory to sys.path
        cmd_line.append("-I")
    elif not env_vars:
        # ignore Python environment variables
        cmd_line.append("-E")
    # Need to preserve the original environment, for in-place testing of
    # shared library builds.
    env = os.environ.copy()
    # But a special flag that can be set to override -- in this case, the
    # caller is responsible to pass the full environment.
    if env_vars.pop("__cleanenv", None):
        env = {}
    env.update(env_vars)
    cmd_line.extend(args)
    p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
    try:
        out, err = p.communicate()
    finally:
        subprocess._cleanup()
        p.stdout.close()
        p.stderr.close()
    rc = p.returncode
    err = strip_python_stderr(err)
    if (rc and expected_success) or (not rc and not expected_success):
        raise AssertionError("Process return code is %d, " "stderr follows:\n%s" % (rc, err.decode("ascii", "ignore")))
    return rc, out, err
开发者ID:JioCloudCompute,项目名称:trollius,代码行数:36,代码来源:test_support.py


示例19: fmenu

def fmenu():
    global vuln
    vuln = []
    if endsub != 1:
        vulnscan()
    logo()
    print("[1] Dork and vuln scan")
    print("[2] Admin page finder")
    print("[3] FTP crawler and vuln scan")
    print("[4] DNS brute")
    print("[5] Enable Tor/Proxy Support")
    print("[6] Misc Options")
    print("[0] Exit\n")
    chce = input(":")

    if chce == '1':
        print(W + "")
        fscan()

    elif chce == '2':
        afsite = input("Enter the site eg target.com: ")
        print(B)
        pwd = os.path.dirname(str(os.path.realpath(__file__)))
        findadmin = subprocess.Popen(pwd + "/modules/adminfinder.py -w modules/adminlist.txt -u " + str(afsite),
                                     shell=True)
        findadmin.communicate()
        subprocess._cleanup()

    elif chce == '3':
        randips = input("How many IP addresses do you want to scan: ")
        print(B)
        pwd = os.path.dirname(str(os.path.realpath(__file__)))
        ftpcrawl = subprocess.Popen(pwd + "/modules/ftpcrawler.py -i " + str(randips), shell=True)
        ftpcrawl.communicate()
        subprocess._cleanup()

    elif chce == '4':
        dnstarg = input("Enter the site eg target.com: ")
        print(B)
        pwd = os.path.dirname(str(os.path.realpath(__file__)))
        dnsbrute = subprocess.Popen(pwd + "/modules/dnsbrute.py -w modules/subdomainsmid.txt -u " + str(dnstarg),
                                    shell=True)
        dnsbrute.communicate()
        subprocess._cleanup()

    elif chce == '5':
        print(W + "")
        enable_proxy()

    elif chce == '0':
        print(R + "\n Exiting ...")
        print(W)
        sys.exit(0)

    elif chce == '6':
        print(W + "")
        os.system('clear')
        logo()
        print("[1] Skip to custom SQLi list checking")
        print("[2] Cloudflare IP Resolver ::= Next Release")
        print("[3] Identify Hash ::= Next Release")
        print("[4] SockStress DDoS Tool ::= Next Release")
        print("[0] Return to main menu")
        chce2 = input(":")
        if chce2 == '1':
            os.system('clear')
            logo()
            try:
                url = [line.strip() for line in open(input("Please Input Custom List Path \n"
                                                       "ie> \n"
                                                       " /home/user/Desktop/samples.txt \n"
                                                       "\n :    :"))]
                classicinj(url)
            except:
                os.system('clear')
                logo()
                print("Target file not found!")
                os.system('clear')
                fmenu()
        elif chce2 == '2':
            os.system('clear')
            logo()
#           cloud()
        elif chce2 == '0':
            fmenu()
开发者ID:alma4rebi,项目名称:V3n0M-Scanner,代码行数:85,代码来源:v3n0m.py


示例20: __init__

    def __init__(self, args, bufsize=0, executable=None,
                 stdin=None, stdout=None, stderr=None,
                 preexec_fn=None, close_fds=False, shell=False,
                 cwd=None, env=None, universal_newlines=False,
                 startupinfo=None, creationflags=0,
                 verbose=False, fork=True):  #new
        
        # do stuff
        self.opts, self.args = None, args
        self.name = args[0]
        self.usage = string.join(string.split(self. __doc__, '\n')[1:], '\n')
        
        # Argument Processing
        self.parser = cmd_parser(usage=self.usage)  # build parser
        self.parser.add_option('-v', '--verbose',  action='store_true',
            dest='verbose', default=verbose, help='enable verbose output.')
        self.parser.add_option('-q', '--quiet',  action='store_false',
            dest='verbose', default=verbose, help='disable verbose output.')

        try: # see if object needs to register parameters with option parser
            register_opts_func = getattr(self, 'register_opts')
            register_opts_func()
        except AttributeError:  pass
        # Option parser
        try:  self.parse_args(args)
        except ValueError:
            # on error or help (-h), defeat run() function, and print \n
            self.run = self.newline
        
        # run supa-class:
        #super(ConsoleAppBase2, self).__init__(self,args,**kw)
        subprocess._cleanup()

        self.stdin = None
        self.stdout = None
        self.stderr = None
        self.pid = None
        self.returncode = None
        self.universal_newlines = universal_newlines

        # Input and output objects. The general principle is like
        # this:
        #
        # Parent                   Child
        # ------                   -----
        # p2cwrite   ---stdin--->  p2cread
        # c2pread    <--stdout---  c2pwrite
        # errread    <--stderr---  errwrite
        if fork:
            (p2cread, p2cwrite,
             c2pread, c2pwrite,
             errread, errwrite) = self._get_handles(stdin, stdout, stderr)
            # need to implement this for the next line... is stdout a tty?
            if c2pwrite <> None:
                    self.istty = os.isatty(c2pwrite)
            else:   self.istty = os.isatty(sys.stdout.fileno())
    
            self._execute_child(args, executable, preexec_fn, close_fds,
                                cwd, env, universal_newlines,
                                startupinfo, creationflags, shell,
                                p2cread, p2cwrite,
                                c2pread, c2pwrite,
                                errread, errwrite)
            if p2cwrite:
                self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
            if c2pread:
                if universal_newlines:
                    self.stdout = os.fdopen(c2pread, 'rU', bufsize)
                else:
                    self.stdout = os.fdopen(c2pread, 'rb', bufsize)
            if errread:
                if universal_newlines:
                    self.stderr = os.fdopen(errread, 'rU', bufsize)
                else:
                    self.stderr = os.fdopen(errread, 'rb', bufsize)
        else:
            self.istty = os.isatty(sys.stdout.fileno())
            returncode = self.run()  # don't want .run() to have to set rt. explicitly
            if returncode:  self.returncode = returncode
            else:           self.returncode = 0
            
        subprocess._active.append(self)
开发者ID:Recaiden,项目名称:pysh,代码行数:82,代码来源:cmdbase.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python subprocess.call函数代码示例发布时间:2022-05-27
下一篇:
Python api.set_score函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap