INNER CODE UNIT · Python
CppExecutor
iamgreggarcia/codesherpa · executors/executor.py:66
class CppExecutor(Executor):
def execute(self, code: str) -> str:
with open("script.cpp", "w") as f:
f.write(code)
try:
subprocess.run(["g++", "script.cpp"], check=True)
output = subprocess.run(
["./a.out"], capture_output=True, text=True, check=True
)
return output.stdout
except subprocess.CalledProcessError as e:
# Here we include e.stderr in the output.
raise subprocess.CalledProcessError(e.returncode, e.cmd, output=e.stderr)
class RustExecutor(Executor):
def execute(self, code: str) -> str:
with open("script.rs", "w") as f: