| 306 | } |
| 307 | |
| 308 | private async _start(): Promise<void> { |
| 309 | const child = this.spawn() |
| 310 | this.child = child |
| 311 | |
| 312 | // Log child output to stdout/stderr and to the log directory. |
| 313 | if (child.stdout) { |
| 314 | child.stdout.on("data", (data) => { |
| 315 | this.logStdoutStream.write(data) |
| 316 | process.stdout.write(data) |
| 317 | }) |
| 318 | } |
| 319 | if (child.stderr) { |
| 320 | child.stderr.on("data", (data) => { |
| 321 | this.logStderrStream.write(data) |
| 322 | process.stderr.write(data) |
| 323 | }) |
| 324 | } |
| 325 | |
| 326 | this.logger.debug(`spawned child process ${child.pid}`) |
| 327 | |
| 328 | await this.handshake(child) |
| 329 | |
| 330 | child.once("exit", (code) => { |
| 331 | this.logger.debug(`inner process ${child.pid} exited unexpectedly`) |
| 332 | this.exit(code || 0) |
| 333 | }) |
| 334 | } |
| 335 | |
| 336 | private spawn(): cp.ChildProcess { |
| 337 | return cp.fork(path.join(__dirname, "entry"), { |