I'm using the subprocess module to execute my C program, and at the end I want to get both the return code and the output returned from the program. I tried this:
result = subprocess.check_output(['src/main', '-n {0}'.format(n)], universal_newlines=True) The above captures the output of the program, it will only raise an error if the return code is non-zero. The point is that I do not want to raise an error on non-zero error code, instead I want to use it in an if statement, and if the return code is non-zero I want to re-run the process.
Now, if I change it to run, and call as:
result = subprocess.run(['src/main', '-n {0}'.format(n)]) Then, I can do result.returncode to get the return code, but when I do result.stdout, it prints None. Is there a way to get both the return code and the actual output?