I am a teacher working on automating student assignment checking and would like the output file generated when I run a student program using subprocess.run to look just like it does when I run it manually.
The following program
import subprocess
import sys
userInput = open("userInput.txt")
with open("output.txt", "w") as fout:
with open("error.txt", "w") as ferr:
result = subprocess.run(["python","hello.py"], stdin=userInput,stdout=fout,stderr=ferr)
with this hello.py
name = input("Your name: ")
age = input("Your age: ")
print('Hello,',name,"you are",age,"years old")
and this userInput.txt
Bob
27
generates the following output.txt
Your name: Your age: Hello, Bob you are 27 years old
How can I get the program to generate an output.txt file that looks the same as when I simply run hello.py (where the stdin also shows up in the stdout).
Your name: Bob
Your age: 27
Hello, Bob you are 27 years old
I am doing this on a Windows 10 system.