Hi,
I am writing a console application with JLine3, which writes its output to the standard output. Testing team wants to be able to redirect the standard output to a file for automation purposes. How do I achieve that? I am attaching a sample program to illustrate what I want.
Main.java
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
public class Main {
public static void main(String[] args) throws Exception {
Terminal terminal = TerminalBuilder.builder().build();
terminal.writer().println("hello world");
terminal.writer().flush();
}
}
Running it as follows makes it print hello world.
> java Main
hello world
But when I run it as
> java Main >a.txt 2>&1
it still prints hello world to the standard output and nothing in a.txt. What should i do to allow it to redirect to a.txt when redirection is specified in the command line?