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; }