Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import subprocess
- import textwrap
- expr = "-123%10"
- def runner(name, cmds, source_fn=None, source=None):
- cmds = [[x.replace("EXPR", expr) for x in y] for y in cmds]
- if source is not None:
- source = textwrap.dedent(source.replace("EXPR", expr))
- with open(source_fn, "w") as f:
- f.write(source)
- print(name + ": ", end="", flush=True)
- try:
- for cmd in cmds:
- subprocess.check_call(cmd)
- except:
- print("Error")
- def main():
- print("Expression: " + expr)
- runner("Python 2.7", [['python2.7', '-c', 'print(EXPR)']])
- runner("Python 3.9", [['python3.9', '-c', 'print(EXPR)']])
- runner("C", [['cc', 'test.c'], ['./a.out']], "test.c", r"""
- #include <stdio.h>
- int main() {printf("%f\n", (double)(EXPR));return 0;}
- """)
- runner("SQLite", [['sqlite3', ':memory:', 'select EXPR;']])
- runner("Node", [['node', '-e', 'require("./test").init()']], "test.js", r"""
- module.exports.init = function () {
- console.log(EXPR);
- };
- """)
- runner("Java", [['javac', 'test.java'], ['java', 'test']], "test.java", r"""
- public class test {
- public static void main(String[] args) {
- System.out.println(EXPR);
- }
- }
- """)
- runner("Go", [['go', 'run', 'test.go']], "test.go", r"""
- package main
- import "fmt"
- func main() {
- fmt.Println(EXPR)
- }
- """)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment