I have been trying to set up process managers for exported Processing sketches on Windows. Since the sketches will be used on permanent installs I have the following requirements for their execution:
Autostart on boot
Restart on crash/exit
Pipe stdout and stderr to log files
I have tested using [pm2](https://pm2.keymetrics.io/) and [nssm](https://nssm.cc/) without success.
Using pm2, the process keeps being restarted without quitting; This means pm2 thinks the sketch crashed while the exe is still running. It will then restart is aka open another process/exe. I end up with about 30 instances of the same sketch running, thus crashing the PC.
Using nssm, nothing runs.
I can fall back to using the native Windows process management tools, with custom-written batch files, but I am wondering what is up with the Processing exports that make these tools not work.
If you have information or insights it would be much appreciated, I’m a bit in the weeds.
Shows that the process directly exit with a zero return code which triggers the auto restart strategy.
I don’t really know how it work internally, I suppose it launches a new detached Java process running the sketch… (this is the case on Linux thought)
I think a solution might be to make a batch script that regularly checks if your application .exe name is still running and if not start it again (with a delay to prevent multiple instances).
EDIT:
Actually I found that Processing is using Launch4j to wrap the exported sketch into an .exe file on Windows. (link to the code)
And it sets the headerType value to gui which in the docs is this:
<headerType>
Type of the header used to wrap the application.
Header type
Launcher
Splash screen
Wait for the application to close
gui
javaw
yes
wrapper waits only if stayAlive is set to true, otherwise it terminates immediately or after closing the splash screen.
console
java
no
always waits and returns application’s exit code.
jniGui32 (beta)
launch4j
yes
always waits and returns application’s exit code.
jniConsole32 (beta)
launch4j
no
always waits and returns application’s exit code.
<stayAlive>
Optional, defaults to false in GUI header, always true in console header. When enabled the launcher waits for the Java application to finish and returns it’s exit code.
The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you do not want a command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if a launch fails for some reason.