Calling a java program from shell script




















I wrote a Java program to say "hello. How can I call this in a shell script? No Account? Sign up. By signing in, you agree to our Terms of Use and Privacy Policy. Already have an account? Sign in. However, I thought of putting the struggle I had to bear to get a shell script to be executed from a Spring-Boot application for future developers. I had to keep the file in the resources directory and had to set the file to be scanned in pom.

It is possible, just exec it as any other program. Just make sure your script has the proper! Also as for if it's good practice, no it's not, especially for Java, but if it saves you a lot of time porting a large script over, and you're not getting paid extra to do it ; save your time, exec the script, and put the porting to Java on your long-term todo list.

Just the same thing that Solaris 5. This double slash may help. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to run Unix shell script from Java code? Ask Question. Asked 12 years, 11 months ago. Active 1 year, 10 months ago.

Viewed k times. It is quite simple to run a Unix command from Java. Improve this question. Lii Vicky Vicky. Things get interesting if that shell script is interactive. Add a comment. Active Oldest Votes. Improve this answer. Milhous Milhous Is it good practice to call scripts from JAVA?

Leave a Reply Cancel reply Your email address will not be published. View Forms in the browser. View PDF Documents. Convert PDF to image. Extract Text from PDF. Replace ImageIO. Convert Image to PDF. Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search.

I have a Java program which passes some parameters to a Servlet. The Servlet enters the info into a DB and returns back the ID of a row created back to the java program that calls it. ARe there any best practice for this? Is this the right way to do it? Exit code is actually meant for returning the success parameter of the program If I do this, then how do I read the contents of opt. Edit: I should have mentioned this before actually I ssh into the other machine using the script..

Hence, I cannot pipe the two. I would not recommend using the exit status to carry data, for the reasons you've stated. I'm not sure if I missed something but it sounds to me that you could just let the first program write to stdout and pipe both programs together, couldn't you? You wouldn't even need a shellscript. In your shell script you can execute the Java Program and store the id in a variable.

For example:. By the way, if you have output in a file called opt. I wouldn't go with option 1 as the range of exit codes you can use is very limited, some of them have special meanings, and it's not portable. I used double quotes in case there are any spaces in the output of command , but I guess that's dumb because your parameter must be a single number! In your case you could either use cat opt.



0コメント

  • 1000 / 1000