Created
June 22, 2023 00:04
-
-
Save drewja/d7881790be45b2eb72378941072b1dbf to your computer and use it in GitHub Desktop.
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/python3 | |
""" | |
A simple script that accepts c statements as arguments, | |
compiles and runs them with tcc (Tiny C Compiler). | |
usage example: | |
./tccrun 'printf("hello %s", "world\n")' 'return 0' | |
It is necessary to enclose arguments in single quotes | |
""" | |
import sys | |
import subprocess | |
# statements may or may not include a semi-colon | |
code = "main(){%s;}" % ';'.join(sys.argv[1:]) | |
# using tcc -w flag to suppress all warnings | |
p = subprocess.run('tcc -run -w -'.split(), | |
input = code, | |
capture_output=True, | |
text = True) | |
print(p.stdout, end="") | |
exit(p.returncode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment