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


Python Popen.communicate方法代码示例

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


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

示例1: addFile

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]
 def addFile(self, sourcefile):
     if self.type in ['RAR', 'RAR5']:
         raise NotImplementedError
     process = Popen('7z a -y "' + self.filepath + '" "' + sourcefile + '"',
                     stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
     process.communicate()
     if process.returncode != 0:
         raise OSError('Failed to add the file.')
开发者ID:ciromattia,项目名称:kcc,代码行数:10,代码来源:comicarchive.py

示例2: __init__

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]
 def __init__(self, filepath):
     self.filepath = filepath
     self.type = None
     if not os.path.isfile(self.filepath):
         raise OSError('File not found.')
     process = Popen('7z l -y -p1 "' + self.filepath + '"', stderr=STDOUT, stdout=PIPE, stdin=PIPE, shell=True)
     for line in process.stdout:
         if b'Type =' in line:
             self.type = line.rstrip().decode().split(' = ')[1].upper()
             break
     process.communicate()
     if process.returncode != 0:
         raise OSError('Archive is corrupted or encrypted.')
     elif self.type not in ['7Z', 'RAR', 'RAR5', 'ZIP']:
         raise OSError('Unsupported archive format.')
开发者ID:ciromattia,项目名称:kcc,代码行数:17,代码来源:comicarchive.py

示例3: run_command

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]
def run_command(cmd, data, location, chw):
    cwd = os.getcwd()

    if location is not None and chw is True:
        cwd = location
    elif location is not None and chw is False:
        cmd = '{0} {1}'.format(cmd, location)

    r = Popen(shlex.split(cmd), stdout=PIPE, stdin=PIPE, stderr=PIPE, cwd=cwd)

    if data is None:
        output = r.communicate()[0].decode('utf-8')
    else:
        output = r.communicate(input=data)[0]

    return output
开发者ID:ttsvetanov,项目名称:polyaxon,代码行数:18,代码来源:git.py

示例4: extract

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]
 def extract(self, targetdir):
     if not os.path.isdir(targetdir):
         raise OSError('Target directory don\'t exist.')
     process = Popen('7z x -y -xr!__MACOSX -xr!.DS_Store -xr!thumbs.db -xr!Thumbs.db -o"' + targetdir + '" "' +
                     self.filepath + '"', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
     process.communicate()
     if process.returncode != 0:
         raise OSError('Failed to extract archive.')
     tdir = os.listdir(targetdir)
     if 'ComicInfo.xml' in tdir:
         tdir.remove('ComicInfo.xml')
     if len(tdir) == 1 and os.path.isdir(os.path.join(targetdir, tdir[0])):
         for f in os.listdir(os.path.join(targetdir, tdir[0])):
             move(os.path.join(targetdir, tdir[0], f), targetdir)
         os.rmdir(os.path.join(targetdir, tdir[0]))
     return targetdir
开发者ID:ciromattia,项目名称:kcc,代码行数:18,代码来源:comicarchive.py

示例5: popen_wrapper

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]
def popen_wrapper(args, universal_newlines=True):
    p = Popen(args, shell=False, stdout=PIPE, stderr=PIPE,
              close_fds=os.name != 'nt', universal_newlines=universal_newlines)

    output, errors = p.communicate()
    return (
        output,
        errors,
        p.returncode
    )
开发者ID:python-bot,项目名称:python-bot,代码行数:12,代码来源:subprocess.py

示例6: extractMetadata

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]
 def extractMetadata(self):
     process = Popen('7z x -y -so "' + self.filepath + '" ComicInfo.xml',
                     stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
     xml = process.communicate()
     if process.returncode != 0:
         raise OSError('Failed to extract archive.')
     try:
         return parseString(xml[0])
     except ExpatError:
         return None
开发者ID:ciromattia,项目名称:kcc,代码行数:12,代码来源:comicarchive.py

示例7: make

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]
def make(base_dir, timeout=5):
    """compile source code.

    return (ok?, msg)"""
    cmd = ['clang++', '-std=c++11', 'main.cpp']
    p = Popen(cmd, stderr=PIPE, cwd=base_dir)
    try:
        p.wait(timeout)
    except TimeoutExpired:
        return False, 'compilation take too much time.'
    else:
        if p.returncode == 0:
            return True, ''
        else:
            return False, p.communicate()[1]
开发者ID:jhonprice,项目名称:yaoj-django,代码行数:17,代码来源:tasks.py

示例8: Run

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import communicate [as 别名]

#.........这里部分代码省略.........
            :type path: str
            """
            logger.error("%s not found", path)
            e3.log.debug('PATH=%s', os.environ['PATH'])
            raise OSError(errno.ENOENT,
                          'No such file or directory, %s not found' % path)

        # Try to send an helpful message if one of the executable has not
        # been found.
        if isinstance(cmds[0], basestring):
            if which(cmds[0], default=None) is None:
                not_found(cmds[0])
        else:
            for cmd in cmds:
                if which(cmd[0], default=None) is None:
                    not_found(cmd[0])

    def wait(self):
        """Wait until process ends and return its status.

        :return: exit code of the process
        :rtype: int
        """
        if self.status is not None:
            # Wait has already been called
            return self.status

        # If there is no pipe in the loop then just do a wait. Otherwise
        # in order to avoid blocked processes due to full pipes, use
        # communicate.
        if self.output_file.fd != subprocess.PIPE and \
                self.error_file.fd != subprocess.PIPE and \
                self.input_file.fd != subprocess.PIPE:
            self.status = self.internal.wait()
        else:
            tmp_input = None
            if self.input_file.fd == subprocess.PIPE:
                tmp_input = self.input_file.get_command()

            (self.out, self.err) = self.internal.communicate(tmp_input)
            self.status = self.internal.returncode

        self.close_files()
        return self.status

    def poll(self):
        """Check the process status and set self.status if available.

        This method checks whether the underlying process has exited
        or not. If it hasn't, then it just returns None immediately.
        Otherwise, it stores the process' exit code in self.status
        and then returns it.

        :return: None if the process is still alive; otherwise, returns
          the process exit status.
        :rtype: int | None
        """
        if self.status is not None:
            # Process is already terminated and wait been called
            return self.status

        result = self.internal.poll()

        if result is not None:
            # Process is finished, call wait to finalize it (closing handles,
            # ...)
            return self.wait()
        else:
            return None

    def kill(self):
        """Kill the process."""
        self.internal.kill()

    def interrupt(self):
        """Send SIGINT CTRL_C_EVENT to the process."""
        # On windows CTRL_C_EVENT is available and SIGINT is not;
        # and the other way around on other platforms.
        interrupt_signal = getattr(signal, 'CTRL_C_EVENT', signal.SIGINT)
        self.internal.send_signal(interrupt_signal)

    def is_running(self):
        """Check whether the process is running.

        :rtype: bool
        """
        if psutil is None:
            # psutil not imported, use our is_running function
            return is_running(self.pid)
        else:
            return self.internal.is_running()

    def children(self):
        """Return list of child processes (using psutil).

        :rtype: list[psutil.Process]
        """
        if psutil is None:
            raise NotImplementedError('Run.children() require psutil')
        return self.internal.children()
开发者ID:AdaCore,项目名称:e3-core,代码行数:104,代码来源:process.py


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