Let's say I have a program that asks for three numbers using scanner, something like this:
Scanner console = new Scanner(System.in);
int[] numbers = new int[3];
System.out.println("Hello!");
for (int i = 0; i<3; i++){
System.out.print("Please enter a number: ");
numbers[i] = console.nextInt();
}
I want to test a program like this by redirecting some input to it, and then redirecting the output to a file.
input.txt
3
4
5
command
java program < input.txt > output.txt
The problem is that the output.txt will look something like this
Hello!
Please enter a number: Please enter a number: Please enter a number:
As opposed to something like this
Hello!
Please enter a number: 3
Please enter a number: 4
Please enter a number: 5
Is there any way to make output.txt look more like the second one? I'm on a Mac, if that changes anything.
I do NOT want to modify the code - I have to run this test for a lot of similar programs.
err.println, then in shell redirect &2 to the file.