The command you ran is nohup
, and it did exit immediately. nohup
started a separate Python process, but that's not the process p
is controlling.
Why are you using nohup
and &
if that isn't the functionality you want? If you simply want to execute a Python subprocess just call:
Process p = Runtime.getRuntime().exec("/usr/bin/python " + filePath);
Note that it's also safer to use the overload of exec
that takes an array, so you don't have to do string-concatenation yourself (and therefore avoid a type of security exploit). The syntax changes slightly to:
Process p = Runtime.getRuntime().exec(new String[]{"/usr/bin/python", filePath});
Or with ProcessBuilder
:
Process p = new ProcessBuilder("/usr/bin/python", filePath).start();