I'm trying to get an HTTP server running from a JXA (JavaScript for Automation) Mac app. This part is easy as easy as:
app.doShellScript("python -m SimpleHTTPServer");
(More info here: https://github.com/JXA-Cookbook/JXA-Cookbook/wiki/Shell-and-CLI-Interactions)
The problem is, after you've done that, the application process halts because the shell script doesn't actually quit.
Well then ... we just need to make the server run as a background process right?. Unfortunately, none of the things I've tried have transferred control back to the JXA app.
Here's what I've tried:
app.doShellScript("nohup python -m SimpleHTTPServer > /dev/null <&- >&- 2>&- & disown");
app.doShellScript("( python -m SimpleHTTPServer > /dev/null & )");
$.system("( python -m SimpleHTTPServer & )");
exit 0
cron
job that would launch the shell script immediately that would launch the server, but it appears there are sandboxing issues with CRON.$.NSTask
It seems that the eventual solution will involve the background process being launch in a way that is completely 100% zero-knowledge detached from the JXA application.
So after a system reboot, it turns out this works:
$.system("nohup python -m SimpleHTTPServer > /dev/null &");
console.log("Non-blocking!");
(Thank you StackOverflow for being my rubber duck.)