From aa795c6c78cac900764bf8c05438fe95bca1a93a Mon Sep 17 00:00:00 2001 From: HitomaruKonpaku Date: Sun, 1 Dec 2024 21:43:28 +0700 Subject: [PATCH] Add child process log --- src/Downloader.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Downloader.ts b/src/Downloader.ts index b2d0132..999ba27 100644 --- a/src/Downloader.ts +++ b/src/Downloader.ts @@ -26,10 +26,32 @@ export class Downloader { args.push(url) logger.verbose(`${cmd} ${args.join(' ')}`) - const spawnOptions: SpawnOptions = { detached: true, stdio: 'ignore', cwd: process.cwd() } + const spawnOptions: SpawnOptions = { + cwd: process.cwd(), + // detached: true, + // stdio: 'inherit', + } + const cp = process.platform === 'win32' ? child_process.spawn(process.env.comspec, ['/c', cmd, ...args], spawnOptions) : child_process.spawn(cmd, args, spawnOptions) + + if (cp.stdout) { + cp.stdout.setEncoding('utf8') + cp.stdout.on('data', (data) => { + const msg = data.toString() + logger.debug(msg) + }) + } + + if (cp.stderr) { + cp.stderr.setEncoding('utf8') + cp.stderr.on('data', (data) => { + const msg = data.toString() + logger.debug(msg) + }) + } + cp.unref() } }