I'm currently the Teaching Assistant for an Introduction to C class. The class is being taught using Visual Studio, but when grading I just use a simple Windows batch script to process all the assignment submissions, compile them, run them on a test file, and redirect the output to a series of text files I can print out, mark up, and hand back to students. The whole process works very well, except for the fact that when I redirect stdin, it does not appear in the redirected stdout the same way it does when the same stdin is typed directly into the console. Because of this, the output of code formatted for the console does not display correctly in the redirected output. The following file snippets show this problem. Does anyone know of a simple solution?
File: example.c
#include <stdio.h>
int main()
{
int v;
printf("Enter a number: ");
scanf("%i", &v);
printf("You entered: %d\n", v);
return 0;
}
File: input.txt
42
Output (Console)
C:\>example.exe
Enter a number: 42
You entered: 42
C:\>
Output (Redirection)
C:\>example.exe < input.txt > output.txt
C:\>more output.txt
Enter a number: You entered: 42
C:\>