linux - Java code to run a shell script which in turn runs another script -


i have gone through various similar questions asked in forum or in web in general none matched situation explained below. need run shell script java. below code:

in $home_folder

run

#!/bin/sh ----- various commands ----- java com.test.web.restapplication --server.port=9090 

start.sh

#!/bin/sh cd $home_folder nohup ./run & 

stop.sh

#!/bin/sh pkill -f restapiapplication cd $home_folder rm -fr nohup.out 

in other folder

runshellscript.java

public class runshellscript {     public static void main(string[] args)     {             string envar = system.getenv("home_folder");             string command = "";             string option = args[0];             switch(option){                     case "start": command += envar+"/start.sh";                                     break;                     case "stop": command += envar+"/stop.sh";             }             try{                     processbuilder pb = new processbuilder("/bin/bash","-c",command);                     process p = pb.start();                     p.waitfor();                     int shellexitstatus = p.exitvalue();                     system.out.println(shellexitstatus);             }catch(exception e){                     e.printstacktrace();             }     } } 

i able execute stop.sh (which kills service , delete nohup.out) code above not start.sh (which runs spring boot servce). exit value 0 on both cases. when tried run start.sh java code above not create nohup.out file stores output of run script. rd_start.sh runs when run command line (./start.sh). in regard? thanks.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -