O Mahajan wrote:I was asked what does the & do in the above command.
This question has nothing to do with Java. It has to do with the operating system. In pretty much most OSes, including Windows, Linux, Solaris, and other forms of Unix shells, the & runs the command in the background.
Campbell Ritchie wrote:Maybe, but will the java tool abey the & symbol? ... the process starts but does not return control to the terminal. If you push the return key afterwards, however, you get control back.
I'm pretty sure that the "&" doesn't make it past the OS Shell; the Java runtime knows nothing about the "&" by the time it executes the program. You can easily test that by printing out the number of arguments passed into main. To prevent having to hit Enter/Return after putting the process in the background, you need to redirect standard output to something other than the console, such as /dev/null or a file. See the explanation by Walter Brameld IV here: http://tldp.org/LDP/abs/html/x9644.html
If I use & it runs and terminates but I have to use enter to reactivate the shell. If I convert the & to an escape sequence it prints it as 0x26. If I put & in the middle of a word it interprets that as terminating the command and what follows produes a “command not found” error.
If I have something which goes into an infinite loop () or starts another thread (Swing) I can regain control of the shell by using & and (later) enter.
No thanks. We have all the government we need. This tiny ad would like you to leave now: