1

I have written a bash function in my .bashrc which is responsible for updating my java jar file and restarting the application with the new jar, as an auto-updating mechanism.

I am trying to use the following java snippet to execute my function from my java code:

Runtime.getRuntime().exec(new String[] { "/bin/bash", "-c", "update-logbot" });

This returns an exit code of 127, indicating that it cannot find the function.

How would I accomplish executing this bash function from the java application?

Raqbit
  • 15
  • 4
  • I think you should look at this: http://stackoverflow.com/questions/1763156/127-return-code-from – Matt Dec 17 '15 at 17:00
  • 1
    Is `update-logbot` in `PATH`? Try absolute path to `update-logbot`. – fukanchik Dec 17 '15 at 17:03
  • The thing is, I wrote the little script directly in .bashrc. I think I might be able to just write seperate files though. – Raqbit Dec 17 '15 at 17:24

1 Answers1

0

If my understanding is right you already have a bash script to close java/jar program and delete it and download new new jar/java program and execute it.

However you would like to achieve the same using Java program.

to achieve this you need a bash script to download the new program into same folder as the old java program with jar name change to next iterative version of the program.

invoke the script using below in the program

proc = Runtime.getRuntime().exec("sh /home/***/Documents/script.sh");

After confirmation of jar/java program copy operation being successful invoke another script to start the new java/app (provide a delayed start of new program in such a way that the new program won't start until older exits)

in the new java program check for existence of older version of program and execute a script to delete or delete it through the java program

you may also require user privilege imitation (user impersonation by the invoked script)to achieve this functionality

snoopy
  • 44
  • 10