function detachedRun()

in lib/cmds/start.ts [489:523]


function detachedRun(options: Options) {
  var file = path.resolve(__dirname, '..', 'webdriver.js');
  var oldSignal = options[Opt.STARTED_SIGNIFIER].getString();
  var oldViaIPC = options[Opt.SIGNAL_VIA_IPC].getBoolean();
  options[Opt.DETACH].value = false;
  options[Opt.STARTED_SIGNIFIER].value = 'server started';
  options[Opt.SIGNAL_VIA_IPC].value = true;
  let args: string[] = [file, commandName].concat(unparseOptions(options));

  var unreffed = false;
  let child = spawn(process.execPath, args, ['ignore', 1, 2, 'ipc']);

  child.on('message', (message: string) => {
    if (message == options[Opt.STARTED_SIGNIFIER].getString()) {
      if (oldSignal) {
        sendStartedSignal(oldSignal, oldViaIPC);
      }
      logger.info('Detached pid: ' + child.pid);
      child.disconnect();
      child.unref();
      unreffed = true;
    }
  });

  child.on('exit', (code: number) => {
    if (!unreffed) {
      if (code == 0) {
        logger.warn('Server never seemed to start, and has now exited');
      } else {
        logger.error('Server never seemed to start, and has probably crashed');
      }
      process.exit(code);
    }
  });
}