A feature that I want my automatic graders to have is to write the output generated by a student's submission to a txt file. The generated txt file will then be compared to another txt file, that has the expected output, and the comparison will determine what the student's end grade is. I am able to successfully generate the student txt files, but I don't like how the txt file looks. For all the input values that I provide to the input argument of subprocess.run, the values themselves are not written and all of the prompts that ask for the values are written on the same line.An example of the resulting format of the generated txt file, for the following test cases, is...
test case 1: ["103\n", "-3\n", "85\n"]
test case 2: ["-10\n", "-1\n", "105\n" ,"98\n"]
This program calculates the letter grade from the integer quiz gradeEnter quiz grade: This program calculates the letter grade from the integer quiz gradeEnter quiz grade: This program calculates the letter grade from the integer quiz gradeEnter quiz grade: Your quiz letter grade is BThis program calculates the letter grade from the integer quiz gradeEnter quiz grade: This program calculates the letter grade from the integer quiz gradeEnter quiz grade: This program calculates the letter grade from the integer quiz gradeEnter quiz grade: This program calculates the letter grade from the integer quiz gradeEnter quiz grade: Your quiz letter grade is AThis resulting format is hard read. Is there an external feature or special argument that I can include within subprocess.run that will generate the exact output you would see if you ran the actual student submission?Desired output:
This program calculates the letter grade from the integer quiz gradeEnter quiz grade: 103This program calculates the letter grade from the integer quiz gradeEnter quiz grade: -3This program calculates the letter grade from the integer quiz gradeEnter quiz grade: 85Your quiz letter grade is BThis program calculates the letter grade from the integer quiz gradeEnter quiz grade: -10This program calculates the letter grade from the integer quiz gradeEnter quiz grade: -1This program calculates the letter grade from the integer quiz gradeEnter quiz grade: 105This program calculates the letter grade from the integer quiz gradeEnter quiz grade: 98Your quiz letter grade is ACode:
input_value_lists = [["103\n", "-3\n", "85\n"], ["-10\n", "-1\n", "105\n","98\n"]]with open(student_txt_file, "w") as txt_file: for list in input_value_lists: for input_value in list: output = subprocess.run(["java", hw_file], input=input_value, capture_output=True, text=True) txt_file.write(output.stdout)I originally thought that I could directly write the input value into the txt file, but that just leads having the input value before the generated output. I've also been looking through the subprocess documentation, but I'm either misunderstanding it (highly likely) or there really isn't any argument that will actually include the input values.