From 2173921f073e2f780af3c4b23e75dbaa8c4a829a Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Sat, 28 Oct 2023 19:28:30 +0100 Subject: [PATCH] fix runcommands missing data (#5477) Signed-off-by: si458 --- agents/meshcore.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index 2cd6d020..c6f00853 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1496,33 +1496,33 @@ function handleServerCommand(data) { if (options.uid == null) break; if (((require('user-sessions').minUid != null) && (options.uid < require('user-sessions').minUid()))) break; // This command can only run as user. } - + var replydata = ""; if (process.platform == 'win32') { if (data.type == 1) { // 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) { sendConsoleText(c.toString()); }); - mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); }); + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); }); + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); }); mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n'); - mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; }); + mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; }); } else if (data.type == 2) { // 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) { sendConsoleText(c.toString()); }); - mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); }); + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); }); + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); }); mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n'); - mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; }); + mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; }); } } else if (data.type == 3) { // Linux shell mesh.cmdchild = require('child_process').execFile('/bin/sh', ['sh'], options); mesh.cmdchild.descriptorMetadata = 'UserCommandsShell'; - mesh.cmdchild.stdout.on('data', function (c) { sendConsoleText(c.toString()); }); - mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); }); + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); }); + mesh.cmdchild.stderr.on('data', function (c) { replydata + c.toString(); }); mesh.cmdchild.stdin.write(data.cmds.split('\r').join('') + '\nexit\n'); - mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; }); + mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; }); } break; }