redirect standard output

105 views
Skip to first unread message

Anand Subramanian

unread,
Aug 1, 2017, 5:02:58 AM8/1/17
to jline-users
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?

Guillaume Nodet

unread,
Aug 1, 2017, 5:29:45 AM8/1/17
to jline...@googlegroups.com
Could you try removing jna and jansi libraries from the classpath before running ?
It looks the behavior is correct only when not using those libraries.
If you have the same behavior, please raise an issue.

--
You received this message because you are subscribed to the Google Groups "jline-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jline-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guillaume Nodet

unread,
Aug 1, 2017, 5:42:57 AM8/1/17
to jline...@googlegroups.com
Yeah, that seems to be the problem.
I have a fix locally, can you raise an issue at github and I'll commit it asap.
Reply all
Reply to author
Forward
0 new messages