async def main(): p1 = subprocess.Popen( [executable, os.path.join(dirname, 'child.py')], stdout=subprocess.PIPE) p2 = subprocess.Popen( [executable, os.path.join(dirname, 'ichild.py')], stdin=p1.stdout, stdout=subprocess.PIPE) out = await p2.stdout.read() assert out == b'4\n'
async def main(): p1 = subprocess.Popen( [executable, os.path.join(dirname, 'child.py')], stdout=subprocess.PIPE) p2 = subprocess.Popen( [executable, os.path.join(dirname, 'ichild.py')], stdin=p1.stdout, stdout=subprocess.PIPE) out = await p2.stdout.read() assert out == b'4\n'.replace(b'\n', os.linesep.encode('latin-1'))
async def __ptrepack(in_store: str, out_store: str): try: os.remove(out_store) except FileNotFoundError: pass before = perf_counter() proc = subprocess.Popen([ 'ptrepack', '--chunkshape=auto', '--propindexes', '--complib=blosc:zstd', '--complevel=9', in_store, out_store ], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) _, stderr = await proc.communicate() return_code = await proc.wait() _logger.debug("Repacking of %s took %f seconds", in_store, perf_counter() - before) if stderr: raise RuntimeError(stderr.decode()) elif return_code != 0: raise RuntimeError(f"ptrepack exited with code {return_code}")
async def update(self, ctx: Context): """ Downloads the latest version of the bot. The command does not change the state of the current running bot. In order for the changes to apply, the files and/or the bot have to be reloaded. """ # TODO maybe allow arguments for better control (using argparse?) process = subprocess.Popen('git pull'.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = map(methodcaller('decode'), await process.communicate()) # TODO output might be over 2000 characters...? description = '```diff\n{0}\n{1}```'.format(stdout, stderr) # TODO relies on there not being both stdout stderr output, embed = Embed(colour=0xcc0000 if stderr else 0x4BB543, description=description) embed.set_author( name='Result:', url='https://github.com/TildeBeta/6X', icon_url= 'https://cdn.discordapp.com/emojis/421819534060814347.png?v=1') await ctx.channel.messages.send(embed=embed)
def _run(self): try: return _subprocess.Popen(self.cmd, stdin=self.stdin, stdout=self.stdout, stderr=self.stderr, **self.popenargs) except FileNotFoundError as fnfe: raise CmdyExecNotFoundError(str(fnfe)) from None
async def child(): p = subprocess.Popen([executable, os.path.join(dirname, 'child.py')], stdin=subprocess.PIPE) try: out = await p.communicate(input=b'x'*10000000) assert False except CancelledError as e: assert e.stdout == b'' assert e.stderr == b'' raise
def spawn_kubectl(self, args, **kw): args = [self.get_kubectl_path()] + list(args) env = self.get_kubectl_environ() if 'env' in kw: env.update(kw['env']) kw['env'] = env self.log.debug(f'running {" ".join(args)}') p = subprocess.Popen(args, **kw) self.log.debug(f'kubectl pid {p.pid}') return p
async def changelog(self, ctx: Context, amount: int = 3): """ Shows the latest changes in the git repository. """ amount = max(min(10, amount), 1) process = subprocess.Popen(f'git log -n {amount}'.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, _ = map(methodcaller('decode'), await process.communicate()) await ctx.channel.messages.send(f'```{stdout}```')
def func(): with subprocess.Popen([sys.executable, '-c', 'print("hello")'], stdout=subprocess.PIPE) as p: data = AWAIT(p.stdout.read()) assert data == b'hello\n'
async def main(): p = subprocess.Popen([executable, '-c', 'import time;time.sleep(1)']) code = await p.wait() assert code == 0
def test_universal(): with pytest.raises(RuntimeError): p = subprocess.Popen([executable, '-m', 'bad'], universal_newlines=True)
async def main(): p = subprocess.Popen(['ping', 'www.python.org'], stdout=subprocess.PIPE) async for line in p.stdout: print('Got:', line.decode('ascii'), end='')