I have a problem with running C++ in my Python programm. I built a Tkinter programm, to get file with c++ code and input file, so that my programm will generate .out file with output. Using subprocess library I managed to compile C++ using:
subprocess.run(['g++', '-o', 'CodeChecker', self.source_code_file_name])*
But next I would like to run my exec file with input stored in input_text variable. Please tell me, why
result = subprocess.run(['./CodeChecker', '<', 'test.in'], capture_output=True, text=True)
is not working.
I tried different variations, but none of it worked.
EDIT: I have a button that calls run_code function.
- self.source_code_file_name contains my c++ source code
- self.input_file is .in type and contains input
Code:
def run_code(self):
try:
os.chdir(self.path) # change working category
subprocess.run(['g++', '-o', 'CodeChecker', self.source_code_file_name])
result = subprocess.run('./CodeChecker < test.in', capture_output=True, text=True, shell=True)
print(result.stdout)
except:
# error
print("error")
Above code works, but I want to replace test.in with variable self.input_file