ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Yes, you can check whether the command line option includes '&' and if so, then you can use this to redirect the stdin. You have to check whether any of the args in main is '&'.
Thank you for the answer, but that won't work for me. The java command line is part of a script and the script is launched in the background. So there's no "&" in the JVM arguments.
I could define my own JVM parameter, but I would rather check in the code if the program is launched in the background. Is this possible?
Well, you have to check for the & in the script command line parameters. Are you using a bash script, or perl? Both these support command line parameters, and you have to just check for them. And if '&' is present, just call java with an option line "BACK", which you can check for in the args string, and redirect the stdin.
If there are no parameters, the value of the $1 will be ""(NULL), so you have no problem in checking for that. And also if there is no $1, there will be no $2 etc..
I am not very good in bash scripting, but if you want, you can build a perl script, which I have some experience, and which will be easier to customize.
But if what you do is simple, you must stick with bash.
Whatever command line parameters I give, 'echo $#' just outputs 0(zero). I don't think that has anything to do with your problem. And, yes '&' is certainly a parameter, and I think you can check for it. I'll try this one with some of my friends and come back.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.