fix runcommands missing data (#5477)

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Oct 28, 2023 at 19:28 UTC 2173921f073e2f780af3c4b23e75dbaa8c4a829a
1 file changed +10 -10
agents/meshcore.js
+10 -10
@@ -1496,33 +1496,33 @@ function handleServerCommand(data) {
1496 if (options.uid == null) break;
1497 if (((require('user-sessions').minUid != null) && (options.uid < require('user-sessions').minUid()))) break; // This command can only run as user.
1498 }
1499 -
1499 + var replydata = "";
1500 if (process.platform == 'win32') {
1501 if (data.type == 1) {
1502 // Windows command shell
1503 mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['cmd'], options);
1504 mesh.cmdchild.descriptorMetadata = 'UserCommandsShell';
1505 - mesh.cmdchild.stdout.on('data', function (c) { sendConsoleText(c.toString()); });
1506 - mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); });
1505 + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
1506 + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); });
1507 mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n');
1508 - mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
1508 + mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
1509 } else if (data.type == 2) {
1510 // Windows Powershell
1511 mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], options);
1512 mesh.cmdchild.descriptorMetadata = 'UserCommandsPowerShell';
1513 - mesh.cmdchild.stdout.on('data', function (c) { sendConsoleText(c.toString()); });
1514 - mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); });
1513 + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
1514 + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); });
1515 mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n');
1516 - mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
1516 + mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
1517 }
1518 } else if (data.type == 3) {
1519 // Linux shell
1520 mesh.cmdchild = require('child_process').execFile('/bin/sh', ['sh'], options);
1521 mesh.cmdchild.descriptorMetadata = 'UserCommandsShell';
1522 - mesh.cmdchild.stdout.on('data', function (c) { sendConsoleText(c.toString()); });
1523 - mesh.cmdchild.stderr.on('data', function (c) { sendConsoleText(c.toString()); });
1522 + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
1523 + mesh.cmdchild.stderr.on('data', function (c) { replydata + c.toString(); });
1524 mesh.cmdchild.stdin.write(data.cmds.split('\r').join('') + '\nexit\n');
1525 - mesh.cmdchild.on('exit', function () { sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
1525 + mesh.cmdchild.on('exit', function () { sendConsoleText(replydata); sendConsoleText("Run commands completed."); delete mesh.cmdchild; });
1526 }
1527 break;
1528 }