The important word in my question is interactive: for a programming contest (UVa online judge), I'm writing interactive java code : it outputs on System.out and waits for responses on System.in.
I want to test the speed of this code, but if I do the interaction manually, my human typing skills are slowing down the execution and the measurement is biased.
Thus, I want a thread/app/script/whatever that sees when my application writes on System.out and (this thread/app/script/whatever) then writes something that is read by my application using its System.in.
My application should communicate using System.in and System.out because that's how it will be judged once I submitted it to the online judge.
I think multithreading wouldn't do the job because System.in is always read from keyboard, not from another thread.
import java.util.Scanner;
public class Main {
public static void main(final String[] args) {
System.out.println("What now?");
final Scanner scanner = new Scanner(System.in);
final String response = scanner.nextLine();
scanner.close();
System.out.println("Finished: " + response);
}
}
How can I make this code run without a human typing on the keyboard?