I'm trying to run a bash script from inside java that will live on after the JVM exits. My current attempt looks something like this:
String[] linCmd = {"/bin/bash", "-c", "\"set +m; shopt -u huponexit; nohup "
+ "myScript.sh 2>&1 > /dev/null &\""};
pb = new ProcessBuilder(linCmd);
//Other stuff to monitor and start pb
But I'm not seeing myScript.sh actually start up (in top or ps). By the way, the reason for the separate bash shell is because I need the set +m
and don't want to corrupt the original with that. Also the nohup
and shopt -u huponexit
may be redundant, but I've tried it without with each alone and can't seem to get it working right.
Any ideas?
Try it without adding the extra quotation marks around your "set +m ... &" By including the entire thing as the third element of that array, you're telling java that this whole thing is the third argument. The quotes should be unneeded, and I think they might interfere.