views:

123

answers:

3

Is it possible to execute a Java program in the background so the user can execute other commands in front of it?

For instance, here is how the console might look for said program:

$ myProgram (executes program)
Program Started! (output from myProgram)
$ (the user can enter another UNIX command while myProgram is still running)

Thanks in advance!

+4  A: 

Background execution is part of the shell. You can add & at the end of the command line to run it in the background.

The background output does not go to the current shell. If that happened, it would be confusing to the user, having to type input while the terminal is still producing output.

EDIT: I just tried "ls &" on cygwin, and the ls output appears in the console. Seems there is a lot of conflicting information on the net! :)

mdma
Mark Szymanski
yep. I just tried this - see my edit.
mdma
My program won't show any output so I think this solution will work, thanks!
Mark Szymanski
That's good, Glad to help. But why did you put in the eample "Program Started" as output from the program, if there is not output? :)
mdma
Well, other than that there isn't any.
Mark Szymanski
*"The background output does not go to the current shell."* This is not true for any UNIX / LINUX shell I'm aware of. If you don't want output from the background command to go to the shell, you have to explicitly redirect it.
Stephen C
*"Seems there is a lot of conflicting information on the net!"* - In other words, you need to check before you post ... if this is outside your area of personal knowledge. :-)
Stephen C
Jonathan Sternberg
A: 

I beleive it's possible to start the program and allow access to the shell... but the user would not see the output.

I do not think its possible to achieve the example scenario you have given.

Jonno
+2  A: 

Best way is to use screen if you dont have it type

sudo apt-get install screen

type

screen

run the command like

java MyClass

press ctrl + (a + d)

to view this window again, type screen -x

Kim Jong Woo
don't forget the `sudo` with the `apt-get` ;)
Mark Szymanski
`screen` is terrific, can't live without. +1 just for mentioning it.
Pascal Thivent