exec("nohup node app/app.js &", sys.puts)
=> sys.puts never gets called (or at least i got bored of waiting =)
Whereas a simple example works just fine:
exec("date", sys.puts)
Does somebody know why does the latter work but not the former?
Francisco
I'm using child_process.exec to call system tasks.
exec("nohup node app/app.js &", sys.puts)
If standard output is a terminal, the command's standard output is
appended to the file `nohup.out'; if that cannot be written to, it is
appended to the file `$HOME/nohup.out'; and if that cannot be written
to, the command is not run.
I have tried with other commands (unicorn in daemon mode or a node
app, for example) and get the same results.
Consider this example, test.js:
var exec = require('child_process').exec
var sys = require('sys')
exec("node app/app.js &", sys.puts) // app.js is an express webapp
=> node test.js
(the callback doesn't get called - the prompt doesn't return - i have to ^C)
Strangely, if the webapp is already running i do get a return (btw NOT
in the error variable - weird)
=> node test.js
null
net:1033
bind(self.fd, arguments[0]);
^
Error: EADDRINUSE, Address already in use
at Server.listen (net:1033:28)
at [object Object].run
(/Users/ftreacy/.kiwi/current/seeds/express/0.11.0/lib/express/core.js:264:12)
at /Users/ftreacy/.kiwi/current/seeds/express/0.11.0/lib/express/dsl.js:76:29
at Object.<anonymous> (/Users/ftreacy/ws/app/app.js:145:1)
at Module._compile (module:384:23)
at Module._loadScriptSync (module:393:16)
at Module.loadSync (module:296:10)
at Object.runMain (module:459:22)
at node.js:168:8
2010/5/27 Ryan Gahl <ryan...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en.
>
I'm using child_process.exec to call system tasks.
exec("nohup node app/app.js &", sys.puts)
=> sys.puts never gets called (or at least i got bored of waiting =)
I think this is a feature, not a bug. If you want to spawn things with node that detach themselves, the thing you spawn needs to exit. node invokes the callback to exec after the child process signals its exit.
If i kill the thing i spawn... then i get the callback.
How would you achieve this though (detach a process)?
I just want to fire a command and forget (i keep track of the process
through a pid file)
2010/5/27 Matt Ranney <m...@ranney.com>:
How would you achieve this though (detach a process)?
This has enlightened me, I realize I was quite ignorant regarding daemons :)
Both look good, i'll be using daemonize shortly.
Francisco
2010/5/27 Matt Ranney <m...@ranney.com>: