Skip to content

Instantly share code, notes, and snippets.

@ikarino
Last active August 29, 2015 14:11
Show Gist options
  • Save ikarino/11790cffc2b59eb3c635 to your computer and use it in GitHub Desktop.
Save ikarino/11790cffc2b59eb3c635 to your computer and use it in GitHub Desktop.
bottle_subprocess
#!/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