diff --git a/discordAudioBot/pdabHandler.mjs b/discordAudioBot/pdabHandler.mjs index f16d5ca..fa80dad 100644 --- a/discordAudioBot/pdabHandler.mjs +++ b/discordAudioBot/pdabHandler.mjs @@ -22,7 +22,7 @@ let botCallback; export const initDiscordBotClient = (clientId, callback, runPDAB = true) => { botCallback = callback; - if (runPDAB) launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, join(__dirname, "./pdab")); + if (runPDAB) launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, false, join(__dirname, "./pdab")); pdabProcess = true; // TODO - Make this more dynamic } diff --git a/modules/subprocessHandler.mjs b/modules/subprocessHandler.mjs index 3d7ad3f..ceb0791 100644 --- a/modules/subprocessHandler.mjs +++ b/modules/subprocessHandler.mjs @@ -13,8 +13,10 @@ const runningProcesses = {}; * @param {string} processName - The name of the process to launch. * @param {string[]} args - The arguments to pass to the process. * @param {boolean} waitForClose - Set this to wait to return until the process exits + * @param {boolean} returnOutput - Set this in addition to 'waitForClose' to return the script output when the process closes + * @param {boolean} waitForClose - Set the current working directory of the process being launched */ -export const launchProcess = (processName, args, waitForClose = false, pcwd = undefined) => { +export const launchProcess = (processName, args, waitForClose = false, returnOutput = false, pcwd = undefined) => { if (!runningProcesses[processName]) { let childProcess; if (pcwd) { @@ -44,18 +46,22 @@ export const launchProcess = (processName, args, waitForClose = false, pcwd = un scriptOutput += data.toString(); }) - let code = new Promise(res => { + let output = new Promise(res => { childProcess.on('exit', (code, signal) => { // Remove reference to the process when it exits delete runningProcesses[processName]; console.log(`${processName} process exited with code ${code} and signal ${signal}`); console.log("Child process console output: ", scriptOutput); - res(code); + // Return the full script output if requested + if (returnOutput === true) { + return res(scriptOutput) + } + return res(code); }) }); if (waitForClose === true) { - return code + return output } console.log(`${processName} process started.`);