Last active
August 29, 2015 14:11
-
-
Save ikarino/11790cffc2b59eb3c635 to your computer and use it in GitHub Desktop.
bottle_subprocess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
@route('/command', method='GET') | |
def out(): | |
stdout = "" | |
stderr = "" | |
command = None | |
command = request.GET.get("command") | |
if command: | |
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
stdout, stderr = proc.communicate() | |
stdout = stdout.decode().rsplit('\n') | |
stderr = stderr.decode().rsplit('\n') | |
return template('command', stdout=stdout, stderr=stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment