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


Python subprocess.PIPE属性代码示例

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


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

示例1: test_communicate

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def test_communicate(self):
        args = PROGRAM_CAT

        @asyncio.coroutine
        def run(data):
            proc = yield from asyncio.create_subprocess_exec(
                                          *args,
                                          stdin=subprocess.PIPE,
                                          stdout=subprocess.PIPE,
                                          loop=self.loop)
            stdout, stderr = yield from proc.communicate(data)
            return proc.returncode, stdout

        task = run(b'some data')
        task = asyncio.wait_for(task, 60.0, loop=self.loop)
        exitcode, stdout = self.loop.run_until_complete(task)
        self.assertEqual(exitcode, 0)
        self.assertEqual(stdout, b'some data') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_subprocess.py

示例2: test_send_signal

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def test_send_signal(self):
        code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
        args = [sys.executable, '-c', code]
        create = asyncio.create_subprocess_exec(*args,
                                                stdout=subprocess.PIPE,
                                                loop=self.loop)
        proc = self.loop.run_until_complete(create)

        @asyncio.coroutine
        def send_signal(proc):
            # basic synchronization to wait until the program is sleeping
            line = yield from proc.stdout.readline()
            self.assertEqual(line, b'sleeping\n')

            proc.send_signal(signal.SIGHUP)
            returncode = (yield from proc.wait())
            return returncode

        returncode = self.loop.run_until_complete(send_signal(proc))
        self.assertEqual(-signal.SIGHUP, returncode) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_subprocess.py

示例3: shell

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def shell(self, request, command, communicate=None,
                    raw=False, chdir=None):
        """Asynchronous execution of a shell command
        """
        if chdir:
            command = 'cd %s && %s' % (chdir, command)
        request.logger.info('Execute shell command: %s', command)
        stdin = subprocess.PIPE if communicate else None
        proc = await create_subprocess_shell(command,
                                             stdin=stdin,
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.PIPE)
        if communicate:
            msg, err = await proc.communicate(to_bytes(communicate))
        else:
            await proc.wait()
            msg = await proc.stdout.read()
            err = await proc.stderr.read()
        if proc.returncode:
            err = err.decode('utf-8').strip()
            raise ShellError(err, proc.returncode)
        return msg if raw else msg.decode('utf-8').strip() 
开发者ID:quantmind,项目名称:lux,代码行数:24,代码来源:app.py

示例4: scan

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def scan(self, payload: Payload, request: Request) -> WorkerResponse:
        """
        Scan a payload using Exiftool

        """
        errors: List[Error] = []
        try:
            p = await create_subprocess_exec(
                self.bin, '-j', '-n', '-', stdout=PIPE, stdin=PIPE, stderr=PIPE
            )
            out, err = await p.communicate(input=payload.content)
            if err:
                self.log.debug(err)
            results = json.loads(out)[0]
        except Exception as err:
            errors.append(
                Error(err, plugin_name=self.plugin_name, payload_id=payload.payload_id)
            )
        return WorkerResponse(results, errors=errors) 
开发者ID:PUNCH-Cyber,项目名称:stoq-plugins-public,代码行数:21,代码来源:exif.py

示例5: scan

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def scan(self, payload: Payload, request: Request) -> WorkerResponse:
        """
        Scan a payload using xorsearch

        """
        result: Dict = {}

        with tempfile.NamedTemporaryFile() as temp_file:
            temp_file.write(payload.content)
            temp_file.flush()
            cmd = [self.bin, '-f', self.terms, temp_file.name]
            p = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
            out, err = await p.communicate()
        for line in out.splitlines():
            _, _, key, _, pos, hit = line.decode().split(maxsplit=5)
            # We are going to skip over hits that are not xor'd
            if key != '00':
                key = f'0x{key}'
                if key not in result:
                    result[key] = []
                result[key].append(
                    {'pos': f'0x{pos.replace("(-1):", "")}', 'match': hit}
                )
        return WorkerResponse(result) 
开发者ID:PUNCH-Cyber,项目名称:stoq-plugins-public,代码行数:26,代码来源:xorsearch.py

示例6: image_convert_to_png

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def image_convert_to_png(image):
    path_imagemagick = _externals["bot"].get_config_option("image.imagemagick") or "/usr/bin/convert"
    cmd = (path_imagemagick, "-", "png:-")

    try:
        proc = yield from asyncio.create_subprocess_exec(
            *cmd,
            stdin = PIPE,
            stdout = PIPE,
            stderr = PIPE )

        (stdout_data, stderr_data) = yield from proc.communicate(input=image)

        return stdout_data

    except FileNotFoundError:
        logger.error("imagemagick not found at path {}".format(path_imagemagick))
        return False 
开发者ID:hangoutsbot,项目名称:hangoutsbot,代码行数:20,代码来源:__init__.py

示例7: task

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def task():
    rfd, wfd = os.pipe()
    args = [sys.executable, '-c', code, str(rfd)]
    proc = yield from asyncio.create_subprocess_exec(
                          *args,
                          pass_fds={rfd},
                          stdout=subprocess.PIPE)

    pipe = open(wfd, 'wb', 0)
    transport, _ = yield from loop.connect_write_pipe(asyncio.Protocol,
                                                      pipe)
    transport.write(b'data')

    stdout, stderr = yield from proc.communicate()
    print("stdout = %r" % stdout.decode())
    transport.close() 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:18,代码来源:subprocess_attach_write_pipe.py

示例8: cat

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def cat(loop):

    #
    # 异步返回:
    #   - 调用接口:
    #
    proc = yield from asyncio.create_subprocess_shell("cat",
                                                      stdin=PIPE,
                                                      stdout=PIPE)
    print("pid: %s" % proc.pid)

    message = "Hello World!"
    print("cat write: %r" % message)

    stdout, stderr = yield from proc.communicate(message.encode('ascii'))
    print("cat read: %r" % stdout.decode('ascii'))

    exitcode = yield from proc.wait()
    print("(exit code %s)" % exitcode) 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:21,代码来源:shell.py

示例9: test_stdin_not_inheritable

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def test_stdin_not_inheritable(self):
        # Tulip issue #209: stdin must not be inheritable, otherwise
        # the Process.communicate() hangs
        @asyncio.coroutine
        def len_message(message):
            code = 'import sys; data = sys.stdin.read(); print(len(data))'
            proc = yield from asyncio.create_subprocess_exec(
                                          sys.executable, '-c', code,
                                          stdin=asyncio.subprocess.PIPE,
                                          stdout=asyncio.subprocess.PIPE,
                                          stderr=asyncio.subprocess.PIPE,
                                          close_fds=False,
                                          loop=self.loop)
            stdout, stderr = yield from proc.communicate(message)
            exitcode = yield from proc.wait()
            return (stdout, exitcode)

        output, exitcode = self.loop.run_until_complete(len_message(b'abc'))
        self.assertEqual(output.rstrip(), b'3')
        self.assertEqual(exitcode, 0) 
开发者ID:hhstore,项目名称:annotated-py-projects,代码行数:22,代码来源:test_subprocess.py

示例10: sysdetails

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def sysdetails(sysd):
    """ a. """
    if not sysd.text[0].isalpha() and sysd.text[0] not in ("/", "#", "@", "!"):
        try:
            neo = "neofetch/neofetch --on --color_blocks on --bold on --cpu_temp=C \
                    --cpu_speed on --cpu_cores physical --kernel_shorthand on \
                    --gpu_brand on --refresh_rate on --gtk_shorthand on --colors=distro  --backend ascii \
                    --source=auto --Redhat source --stdout"
            fetch = await asyncrunapp(
                neo,
                stdout=asyncPIPE,
                stderr=asyncPIPE,
            )

            stdout, stderr = await fetch.communicate()
            result = str(stdout.decode().strip()) \
                + str(stderr.decode().strip())

            await sysd.edit("sysd Result: `" + result + "`")
        except FileNotFoundError:
            await sysd.edit("`Hey, on mkaraniya/BotHub install .neofetch first kthx`") 
开发者ID:mkaraniya,项目名称:BotHub,代码行数:23,代码来源:sysd.py

示例11: test_empty_input

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def test_empty_input(self):
        @asyncio.coroutine
        def empty_input():
            code = 'import sys; data = sys.stdin.read(); print(len(data))'
            proc = yield from asyncio.create_subprocess_exec(
                                          sys.executable, '-c', code,
                                          stdin=asyncio.subprocess.PIPE,
                                          stdout=asyncio.subprocess.PIPE,
                                          stderr=asyncio.subprocess.PIPE,
                                          close_fds=False,
                                          loop=self.loop)
            stdout, stderr = yield from proc.communicate(b'')
            exitcode = yield from proc.wait()
            return (stdout, exitcode)

        output, exitcode = self.loop.run_until_complete(empty_input())
        self.assertEqual(output.rstrip(), b'0')
        self.assertEqual(exitcode, 0) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:20,代码来源:test_subprocess.py

示例12: test_read_stdout_after_process_exit

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def test_read_stdout_after_process_exit(self):
        @asyncio.coroutine
        def execute():
            code = '\n'.join(['import sys',
                              'for _ in range(64):',
                              '    sys.stdout.write("x" * 4096)',
                              'sys.stdout.flush()',
                              'sys.exit(1)'])

            fut = asyncio.create_subprocess_exec(
                sys.executable, '-c', code,
                stdout=asyncio.subprocess.PIPE,
                loop=self.loop)

            process = yield from fut
            while True:
                data = yield from process.stdout.read(65536)
                if data:
                    yield from asyncio.sleep(0.3, loop=self.loop)
                else:
                    break

        self.loop.run_until_complete(execute()) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:25,代码来源:test_subprocess.py

示例13: start

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def start(self):
        """ Launch the task """
        try:
            flags_raw = self.params['program'][0].split(' -')
            flags = [flags_raw[0]]

            if len(flags_raw) > 1:
                for each_flag in flags_raw[1:]:
                    flags.append('-' + each_flag)

            if self.params.get('special', None):
                self.command = ['nmap', '-oX', '-'] + flags + self.params["special"] + [self.target]
            else:
                self.command = ['nmap', '-oX', '-'] + flags + [self.target]
            print("Starting: ", ' '.join(self.command))
            self.proc = await asyncio.create_subprocess_exec(*self.command, stdin=PIPE, stdout=PIPE, stderr=PIPE)

            await self.set_status("Working", 0, "")
            loop = asyncio.get_event_loop()
            loop.create_task(self.read_stdout())
            loop.create_task(self.read_stderr())
            # self.spawn_status_poller()
        except Exception as exc:
            await self.set_status("Aborted", -1, str(exc)) 
开发者ID:c0rvax,项目名称:project-black,代码行数:26,代码来源:nmap_task.py

示例14: start

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def start(self):
        """ Launch the task and readers of stdout, stderr """
        try:
            self.command = ['amass', 'enum' '-d'] + [self.target] + [self.params['program']['argv']]
            print(' '.join(self.command))
            self.proc = await asyncio.create_subprocess_shell(' '.join(self.command), stdout=PIPE, stderr=PIPE)

            # 1337 is hardcoded to show frontend that we don't track progress here
            await self.set_status("Working", progress=1337)
    
            # Launch readers
            loop = asyncio.get_event_loop()
            loop.create_task(self.read_stdout())
            loop.create_task(self.read_stderr())

        except Exception as exc:
            print(str(exc))
            self.logger.error(str(exc))
            await self.set_status("Aborted", 0, str(exc)) 
开发者ID:c0rvax,项目名称:project-black,代码行数:21,代码来源:amass_task.py

示例15: start

# 需要导入模块: from asyncio import subprocess [as 别名]
# 或者: from asyncio.subprocess import PIPE [as 别名]
def start(self):
        """ Launch the task and readers of stdout, stderr """
        print(self.params, self.target)
        try:
            self.command = ['sudo', 'masscan'] + [','.join(self.target)] + ['-oX', '-'] + self.params['program']

            self.proc = await asyncio.create_subprocess_shell(' '.join(self.command), stdout=PIPE, stderr=PIPE)

            await self.set_status("Working", progress=0)
    
            # Launch readers
            loop = asyncio.get_event_loop()
            loop.create_task(self.read_stdout())
            loop.create_task(self.read_stderr())

            # Launch status poller
            loop.create_task(self.spawn_status_poller())
        except Exception as exc:
            await self.set_status("Aborted", 0, str(exc)) 
开发者ID:c0rvax,项目名称:project-black,代码行数:21,代码来源:masscan_task.py


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