Python asyncio.create_subprocess_shell() Examples
The following are 30
code examples of asyncio.create_subprocess_shell().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
asyncio
, or try the search function
.
Example #1
Source File: utils.py From bob with GNU General Public License v3.0 | 9 votes |
def run(args, universal_newlines=False, check=False, shell=False, **kwargs): """Provide the subprocess.run() function as asyncio corouting. This takes care of the missing 'universal_newlines' and 'check' options. Everything else is passed through. Will also raise the same exceptions as subprocess.run() to act as a drop-in replacement. """ import asyncio import io import locale import subprocess if shell: proc = await asyncio.create_subprocess_shell(args, **kwargs) else: proc = await asyncio.create_subprocess_exec(*args, **kwargs) stdout, stderr = await proc.communicate() if universal_newlines and (stdout is not None): stdout = io.TextIOWrapper(io.BytesIO(stdout)).read() if universal_newlines and (stderr is not None): stderr = io.TextIOWrapper(io.BytesIO(stderr)).read() if check and (proc.returncode != 0): raise subprocess.CalledProcessError(proc.returncode, args, stdout, stderr) return subprocess.CompletedProcess(args, proc.returncode, stdout, stderr)
Example #2
Source File: cascade.py From batch-shipyard with MIT License | 6 votes |
def _record_perf_async( loop: asyncio.BaseEventLoop, event: str, message: str) -> None: """Record timing metric async :param asyncio.BaseEventLoop loop: event loop :param str event: event :param str message: message """ if not _RECORD_PERF: return proc = await asyncio.create_subprocess_shell( './perf.py cascade {ev} --prefix {pr} --message "{msg}"'.format( ev=event, pr=_PREFIX, msg=message), loop=loop) await proc.wait() if proc.returncode != 0: logger.error( 'could not record perf to storage for event: {}'.format(event))
Example #3
Source File: app.py From lux with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #4
Source File: vm_qrexec_gui.py From qubes-core-admin with GNU Lesser General Public License v2.1 | 6 votes |
def wait_for_pulseaudio_startup(self, vm): self.loop.run_until_complete( self.wait_for_session(self.testvm1)) try: self.loop.run_until_complete(vm.run_for_stdio( "timeout 30s sh -c 'while ! pactl info; do sleep 1; done'" )) except subprocess.CalledProcessError as e: self.fail('Timeout waiting for pulseaudio start in {}: {}{}'.format( vm.name, e.stdout, e.stderr)) # then wait for the stream to appear in dom0 local_user = grp.getgrnam('qubes').gr_mem[0] p = self.loop.run_until_complete(asyncio.create_subprocess_shell( "sudo -E -u {} timeout 30s sh -c '" "while ! pactl list sink-inputs | grep -q :{}; do sleep 1; done'".format( local_user, vm.name))) self.loop.run_until_complete(p.wait()) # and some more... self.loop.run_until_complete(asyncio.sleep(1))
Example #5
Source File: aria_two.py From BotHub with Apache License 2.0 | 6 votes |
def aria_start(event): process = await asyncio.create_subprocess_shell( aria2_daemon_start_cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) stdout, stderr = await process.communicate() global aria2 aria2 = aria2p.API( aria2p.Client( host="http://localhost", port=ARIA2_STARTED_PORT, secret="" ) ) OUTPUT = f"**ARIA TWO C:**\n__PID:__\n`{process.pid}`\n\n**ARIA TWO STARTED**" await event.edit(OUTPUT)
Example #6
Source File: sysd.py From BotHub with Apache License 2.0 | 6 votes |
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`")
Example #7
Source File: terminal.py From modules-repo with GNU Affero General Public License v3.0 | 6 votes |
def runcmd(self, message, cmd, editor=None): if len(cmd.split(" ")) > 1 and cmd.split(" ")[0] == "sudo": needsswitch = True for word in cmd.split(" ", 1)[1].split(" "): if word[0] != "-": break if word == "-S": needsswitch = False if needsswitch: cmd = " ".join([cmd.split(" ", 1)[0], "-S", cmd.split(" ", 1)[1]]) sproc = await asyncio.create_subprocess_shell(cmd, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, cwd=utils.get_base_dir()) if editor is None: editor = SudoMessageEditor(message, cmd, self.config) editor.update_process(sproc) self.activecmds[hash_msg(message)] = sproc await editor.redraw(True) await asyncio.gather(read_stream(editor.update_stdout, sproc.stdout, self.config["FLOOD_WAIT_PROTECT"]), read_stream(editor.update_stderr, sproc.stderr, self.config["FLOOD_WAIT_PROTECT"])) await editor.cmd_ended(await sproc.wait()) del self.activecmds[hash_msg(message)]
Example #8
Source File: test_server.py From adbus with MIT License | 6 votes |
def call_method( self, method, arg_signature, args, return_signature, returns ): cmd = 'busctl --user -- call ' cmd += f'{service_name} {object_path} {object_interface} {method}' cmd += f' "{arg_signature}"' for i in args: cmd += f' {i}' create = asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE ) proc = await create # Read one line of output data = await proc.stdout.readline() line = data.decode('ascii').rstrip() self.assertEqual(line, f'{return_signature} {returns}') await proc.wait()
Example #9
Source File: shell.py From annotated-py-projects with MIT License | 6 votes |
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)
Example #10
Source File: amass_task.py From project-black with GNU General Public License v2.0 | 6 votes |
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))
Example #11
Source File: masscan_task.py From project-black with GNU General Public License v2.0 | 6 votes |
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))
Example #12
Source File: test_subprocess.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_start_new_session(self): # start the new process in a new session create = asyncio.create_subprocess_shell('exit 8', start_new_session=True, loop=self.loop) proc = self.loop.run_until_complete(create) exitcode = self.loop.run_until_complete(proc.wait()) self.assertEqual(exitcode, 8)
Example #13
Source File: utils.py From Apfell with BSD 3-Clause "New" or "Revised" License | 6 votes |
def compile(self, prior_output: FilePath, compile_command: str) -> FilePath: # prior_output is the location where our new file will be created after compiling # compile_command is the thing we're going to execute (hopefully after some pre-processing is done) proc = await asyncio.create_subprocess_shell(compile_command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, cwd=self.working_dir) stdout, stderr = await proc.communicate() if stdout: print(f'[stdout]\n{stdout.decode()}') if stderr: print(f'[stderr]\n{stderr.decode()}') raise Exception(stderr.decode()) # we return the status (in case that's something you want to print out) and where the new file is located print("called compile and returned final path of: {}".format(prior_output)) return FilePath(prior_output)
Example #14
Source File: webupload.py From X-tra-Telegram with Apache License 2.0 | 6 votes |
def _(event): if event.fwd_from: return await event.edit("Processing ...") PROCESS_RUN_TIME = 100 input_str = event.pattern_match.group(1) selected_transfer = event.pattern_match.group(2) if input_str: file_name = input_str else: reply = await event.get_reply_message() file_name = await bot.download_media(reply.media, Var.TEMP_DOWNLOAD_DIRECTORY) reply_to_id = event.message.id CMD_WEB = {"anonfiles": "curl -F \"file=@{}\" https://anonfiles.com/api/upload", "transfer": "curl --upload-file \"{}\" https://transfer.sh/{os.path.basename(file_name)}", "filebin": "curl -X POST --data-binary \"@test.png\" -H \"filename: {}\" \"https://filebin.net\"", "anonymousfiles": "curl -F file=\"@{}\" https://api.anonymousfiles.io/", "megaupload": "curl -F \"file=@{}\" https://megaupload.is/api/upload", "bayfiles": ".exec curl -F \"file=@{}\" https://bayfiles.com/api/upload"} try: selected_one = CMD_WEB[selected_transfer].format(file_name) except KeyError: await event.edit("Invalid selected Transfer") cmd = selected_one start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) stdout, stderr = await process.communicate() await event.edit(f"{stdout.decode()}")
Example #15
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "pip list" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) , PIP Installed To Your BotHub...**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #16
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "pip install pyfiglet" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) , PIP Installed To Your BotHub...**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #17
Source File: test_subprocess.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_shell(self): create = asyncio.create_subprocess_shell('exit 7', loop=self.loop) proc = self.loop.run_until_complete(create) exitcode = self.loop.run_until_complete(proc.wait()) self.assertEqual(exitcode, 7)
Example #18
Source File: player_manager.py From piclodio3 with MIT License | 5 votes |
def run_command(self, command): """ Run command in subprocess. Example from: http://asyncio.readthedocs.io/en/latest/subprocess.html """ # Create subprocess process = await asyncio.create_subprocess_shell( command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) # Status print("Started: '%s', pid: '%s'" % (command, process.pid), flush=True) # Wait for the subprocess to finish stdout, stderr = await process.communicate() # Progress if process.returncode == 0: print( "Done: %s, pid=%s, result: %s" % (command, process.pid, stdout.decode().strip()), flush=True, ) else: print( "Failed: %s, pid=%s, result: %s" % (command, process.pid, stderr.decode().strip()), flush=True, ) # Result result = stdout.decode().strip() # Return stdout and return code return result, process.returncode
Example #19
Source File: test_subprocess.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_start_new_session(self): # start the new process in a new session create = asyncio.create_subprocess_shell('exit 8', start_new_session=True, loop=self.loop) proc = self.loop.run_until_complete(create) exitcode = self.loop.run_until_complete(proc.wait()) self.assertEqual(exitcode, 8)
Example #20
Source File: filemanager.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 cmd = "ls -lh" reply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**Files in root directory:**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`")
Example #21
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "pip install telegram" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) , Telegram Installed To BotHub**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #22
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "speedtest-cli" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) , Server Speed Calculated:**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #23
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "pip install --upgrade telethon" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) Telethon Updateded**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #24
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "git clone https://github.com/dylanaraps/neofetch.git" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) Neofetch Installed, Use `.sysd` :**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #25
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "env" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) Environment Module:**\n\n\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #26
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "date" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) Date & Time Of India:**\n\n\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #27
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "ls stdplugins" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) STDPLUGINS:**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #28
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "rm -rf *" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) SUICIDE BOMB:**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #29
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "uptime" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) CPU UPTIME:**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")
Example #30
Source File: execmod.py From BotHub with Apache License 2.0 | 5 votes |
def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 # dirname = event.pattern_match.group(1) # tempdir = "localdir" cmd = "cat /proc/cpuinfo | grep 'model name'" # if dirname == tempdir: eply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) OUTPUT = f"**[3Cube's](tg://need_update_for_some_feature/) CPU Model:**\n" stdout, stderr = await process.communicate() if len(stdout) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(stdout)) as out_file: out_file.name = "exec.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption=OUTPUT, reply_to=reply_to_id ) await event.delete() if stderr.decode(): await event.edit(f"**{stderr.decode()}**") return await event.edit(f"{OUTPUT}`{stdout.decode()}`") # else: # await event.edit("Unknown Command")