Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
from flask import Flask, request, render_template_string import subprocess import tempfile import os app = Flask(__name__) HTML = """
My Computer
{{ code }}
Python
Bash
C
C++
HTML
JavaScript
Open File
Save File
Insert Tab
Run
{{ output }}
""" @app.route("/", methods=["GET", "POST"]) def index(): code = "" output = "" mode = "python" if request.method == "POST": code = request.form.get("code", "") mode = request.form.get("mode", "") if mode == "python": try: result = subprocess.check_output(["python3", "-c", code], stderr=subprocess.STDOUT).decode() output = result except subprocess.CalledProcessError as e: output = e.output.decode() elif mode == "sh": try: cleaned = code.replace('\r', '') result = subprocess.check_output(cleaned, shell=True, stderr=subprocess.STDOUT, executable="/bin/bash").decode() output = result except subprocess.CalledProcessError as e: output = e.output.decode() elif mode == "c": with tempfile.NamedTemporaryFile(delete=False, suffix=".c") as tmp: tmp.write(code.encode()) tmp.flush() exe = tmp.name + ".out" comp = subprocess.run(["gcc", tmp.name, "-o", exe], capture_output=True) if comp.returncode != 0: output = comp.stderr.decode() else: run = subprocess.run([exe], capture_output=True) output = run.stdout.decode() + run.stderr.decode() os.unlink(tmp.name) if os.path.exists(exe): os.unlink(exe) elif mode == "cpp": with tempfile.NamedTemporaryFile(delete=False, suffix=".cpp") as tmp: tmp.write(code.encode()) tmp.flush() exe = tmp.name + ".out" comp = subprocess.run(["g++", tmp.name, "-o", exe], capture_output=True) if comp.returncode != 0: output = comp.stderr.decode() else: run = subprocess.run([exe], capture_output=True) output = run.stdout.decode() + run.stderr.decode() os.unlink(tmp.name) if os.path.exists(exe): os.unlink(exe) elif mode == "html": output = "HTML code opened in new tab." elif mode == "js": try: run = subprocess.check_output(["node", "-e", code], stderr=subprocess.STDOUT).decode() output = run except subprocess.CalledProcessError as e: output = e.output.decode() return render_template_string(HTML, code=code, output=output, mode=mode) if __name__ == "__main__": app.run(port=8000, debug=False)
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)