Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a .jar file which is console based. I would like to run it in Linux via SSH. So far I am able to run it and see the output.

However, after disconnecting and then reconnecting to the terminal, how can I access the output from the Java program again?

share|improve this question
    
minecraft server remote administration? –  dashboard Apr 5 '13 at 2:36
    
ha nice guess!, though i play minecraft, not rly that ;) –  Krimson Apr 5 '13 at 3:04

2 Answers 2

up vote 5 down vote accepted

Do you want to leave the Java application running, even after you disconnect? If so, install screen. screen allows you to create persistent sessions allowing you to keep programs/scripts running in their own session even after you log out of SSH.

If you're on Ubuntu or any Debian-based distro, installing screen is easy:

# apt-get install screen

To create a session:

$ screen -R sessionName

Start your Java application in the session and then when you are ready to detach and let it run in the background, type Ctrl+A and then D. You can then safely disconnect from the SSH session.

To re-attach to the screen session, execute:

$ screen -r sessionName

The Screen man pages describe all of the other arguments and flags if you want to learn more.


If you simply want to save the output of the application for later reading, redirect stdout to a file:

$ java -jar my.jar > output.txt
share|improve this answer
    
your instructions were a breeze to follow through! Well written! –  Krimson Apr 5 '13 at 3:08

alternately you could also use Tmux, a more modern alternative to screen

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.