I am currently developing a Java system that communicates with node.js using socket.io. The system and the script are on the same server. How can I execute the script from my Java code and keep it alive from my app?
Note when using process builder the path to your JavaScript file is an argument and "node" is the command, so they need to be separated:
ProcessBuilder pb = new ProcessBuilder("node", "app.js");
This is also useful for inheriting its console output, starting the process and getting the reference to the process:
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
Process p = pb.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With