Skip to content

Instantly share code, notes, and snippets.

@drewja
Created June 22, 2023 00:04
Show Gist options
  • Save drewja/d7881790be45b2eb72378941072b1dbf to your computer and use it in GitHub Desktop.
Save drewja/d7881790be45b2eb72378941072b1dbf to your computer and use it in GitHub Desktop.
#!/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