From 440cad5b50b6a697d51ee2312e02a372a3e6ce4c Mon Sep 17 00:00:00 2001 From: si458 Date: Sat, 12 Apr 2025 11:03:44 +0100 Subject: [PATCH] runcommands now shows live output in console instead of after finishing #6948 Signed-off-by: si458 --- agents/meshcore.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index 5a7faaf1..e0c31907 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1556,14 +1556,13 @@ function handleServerCommand(data) { // Windows command shell mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['cmd'], options); mesh.cmdchild.descriptorMetadata = 'UserCommandsShell'; - mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); }); - mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); }); + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); }); + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); }); mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n'); mesh.cmdchild.on('exit', function () { if (data.reply) { mesh.SendCommand({ action: 'msg', type: 'runcommands', result: replydata, sessionid: data.sessionid, responseid: data.responseid }); } else { - sendConsoleText(replydata); sendConsoleText("Run commands completed."); } delete mesh.cmdchild; @@ -1572,14 +1571,13 @@ function handleServerCommand(data) { // Windows Powershell mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], options); mesh.cmdchild.descriptorMetadata = 'UserCommandsPowerShell'; - mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); }); - mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); }); + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); }); + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); }); mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n'); mesh.cmdchild.on('exit', function () { if (data.reply) { mesh.SendCommand({ action: 'msg', type: 'runcommands', result: replydata, sessionid: data.sessionid, responseid: data.responseid }); } else { - sendConsoleText(replydata); sendConsoleText("Run commands completed."); } delete mesh.cmdchild; @@ -1589,14 +1587,13 @@ function handleServerCommand(data) { // Linux shell mesh.cmdchild = require('child_process').execFile('/bin/sh', ['sh'], options); mesh.cmdchild.descriptorMetadata = 'UserCommandsShell'; - mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); }); - mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); }); + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); }); + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); }); mesh.cmdchild.stdin.write(data.cmds.split('\r').join('') + '\nexit\n'); mesh.cmdchild.on('exit', function () { if (data.reply) { mesh.SendCommand({ action: 'msg', type: 'runcommands', result: replydata, sessionid: data.sessionid, responseid: data.responseid }); } else { - sendConsoleText(replydata); sendConsoleText("Run commands completed."); } delete mesh.cmdchild;