Improve command logging and update function to async

This commit is contained in:
Logan Cusano
2023-03-26 00:44:33 -04:00
parent d7878535b5
commit 7c9be47b64
2 changed files with 11 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
import { getDeviceID } from '../utilities/configHandler.js';
// Modules
import alsaInstance from 'alsa-capture';
import { executeAsyncConsoleCommand } from "../utilities/executeConsoleCommand.js";
import executeAsyncConsoleCommand from "../utilities/executeConsoleCommand.js";
// Debug
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
// Global Vars

View File

@@ -1,13 +1,14 @@
// Modules
import { promisify } from 'util';
import { exec } from "child_process";
// Debug
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
// Global Vars
const log = new ModuleDebugBuilder("bot", "executeConsoleCommand");
const exec = promisify(require('child_process').exec);
const execCommand = promisify(exec);
export default function executeAsyncConsoleCommand(consoleCommand) {
export async function executeAsyncConsoleCommand(consoleCommand) {
// Check to see if the command is a real command
// TODO needs to be improved
const acceptableCommands = [ "arecord -L" ];
@@ -15,8 +16,13 @@ export default function executeAsyncConsoleCommand(consoleCommand) {
log.WARN("Console command is not acceptable: ", consoleCommand);
return undefined;
}
const tempOutput = exec();
log.DEBUG("Running console command: ", consoleCommand);
const tempOutput = await execCommand(consoleCommand);
const output = tempOutput.stdout.trim();
log.DEBUG("Executed Console Command Response: ", output)
// TODO add some error checking
return tempOutput.stdout.trim();
return output;
}