discord_bot/util/executeCommand.js
SileNce5k e79d2a7a7e
All checks were successful
CI / CI (push) Successful in 22s
Add output to executeCommand return
2025-06-24 03:40:44 +02:00

15 lines
No EOL
611 B
JavaScript

const { execFileSync } = require('child_process');
module.exports = function(command, commandArgs, verbose=false) {
if (typeof command !== 'string' || !Array.isArray(commandArgs)) return { error: true };
console.log("Executing:", command, commandArgs.join(" "));
let output;
try {
output = execFileSync(command, commandArgs, {encoding: 'utf8'})
if (output.length !== 0 && verbose)
console.log(output)
} catch (error) {
console.error(`Error executing ${command} command:`, error);
return { error: true };
}
return { error: false, output};
}