You can do this with the nohup command. Here is an example.
$ cat Foo.java public class Foo { public static void main(String[] args) throws InterruptedException { for(int i = 0 ; i < 1000 ; i++) { System.out.println(i); Thread.sleep(1000); } } } $ javac Foo.java $ nohup java Foo > foo.txt & [3] 29542 $ cat foo.txt 0 1 2 3 4 5 $ exit
<<restart shell β
$ cat foo.txt 0 1 ... 29 30
The reason this does not work with screen is because screen does not interpret your arguments like the shell does. If you did this with screen , it would work:
screen /bin/bash -c 'java Foo > foo.txt'
mpontillo
source share