當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。