Improve command logging and update function to async
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user