Compile a C/C++ Program and store standard output in a File via Python
问题 Let's say I have a C/C++ file named userfile.c . Using Python, how can I invoke the local gcc compiler so that the file is compiled and an executable is made? More specifically, I would like to provide some input (stdin) via some file input.txt and I want to save the standard output into another file called output.txt . I saw some documentation that I will need to use subprocess, but I'm not sure how to call that and how to provide custom input. 回答1: A simple solution will be as given below: