2

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!

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

7 Comments

So to execute the command in the background I would have to type it like this: myProgram &?
My program won't show any output so I think this solution will work, thanks!
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? :)
Well, other than that there isn't any.
"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.
|
2

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

2 Comments

don't forget the sudo with the apt-get ;)
screen is terrific, can't live without. +1 just for mentioning it.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.