From c058bf3414bd501405582396d12de2fbf0b85817 Mon Sep 17 00:00:00 2001 From: Lightemerald Date: Mon, 26 Jun 2023 10:35:32 +0200 Subject: [PATCH] Better Handling of process --- index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e18d6ec..6d8ddef 100644 --- a/index.js +++ b/index.js @@ -156,8 +156,9 @@ async function startBot(accountName) { }); childProcess.stdout.on('data', (data) => { - console.log(`[${accountName}] STDOUT: ${data.toString().trim()}`); - if (data.includes('Press enter') || data.includes('Press any key')) { + const output = data.toString().trim(); + console.log(`[${host}][${accountName}] STDOUT: ${output}`); + if (output.includes('Press enter') || output.includes('Press any key')) { setTimeout(() => { childProcess.stdin.write('\n'); }, 1000); @@ -165,7 +166,13 @@ async function startBot(accountName) { }); childProcess.stderr.on('data', (data) => { - console.error(`[${accountName}] STDERR: ${data.toString().trim()}`); + const output = data.toString().trim(); + console.log(`[${host}][${accountName}] STDERR: ${output}`); + if (output.includes('Press enter') || output.includes('Press any key')) { + setTimeout(() => { + childProcess.stdin.write('\n'); + }, 1000); + } }); childProcess.on('exit', (code) => {