Description
- Node.js Version: 7.9.0
- OS: Windows 10
- Scope (install, code, runtime, meta, other?): Code
- Module (and version) (if relevant):
child_process
Is there anyway to detect if a process has successfully spawned? There's an error
event that I can listen to, but no success
event, so it seems that I have no guarantee that the process successfully spawned until I start actually writing to its streams and get errors.
I have found that I can check proc.pid
right after spawn
ing, and if I pass in a faulty path, it's undefined.
If I pass in the correct path, it's set to a number, which seems promising. However, someone on SO said that the spawning might still fail after the OS gives back a pid.
What exactly is guaranteed after the spawn
function returns? At what point in the spawning process are we? And can I rely on this proc.pid === undefined
technique? If not, how can I at least asynchronously know if the process successfully spawned? Why is there no success
callback?