Mark Szymanski
Mark Szymanski

Reputation: 58050

Execute Command Line Java program in background

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!

Upvotes: 2

Views: 12010

Answers (3)

KJW
KJW

Reputation: 15251

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

Upvotes: 2

mdma
mdma

Reputation: 57707

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! :)

Upvotes: 6

Jonno
Jonno

Reputation: 799

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.

Upvotes: 0

Related Questions