runcommands now shows live output in console instead of after finishing #6948

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

si458 committed Apr 12, 2025 at 11:03 UTC 440cad5b50b6a697d51ee2312e02a372a3e6ce4c
1 file changed +6 -9
agents/meshcore.js
+6 -9
@@ -1556,14 +1556,13 @@ function handleServerCommand(data) {
1556 // Windows command shell
1557 mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['cmd'], options);
1558 mesh.cmdchild.descriptorMetadata = 'UserCommandsShell';
1559 - mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
1560 - mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); });
1559 + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); });
1560 + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); });
1561 mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n');
1562 mesh.cmdchild.on('exit', function () {
1563 if (data.reply) {
1564 mesh.SendCommand({ action: 'msg', type: 'runcommands', result: replydata, sessionid: data.sessionid, responseid: data.responseid });
1565 } else {
1566 - sendConsoleText(replydata);
1566 sendConsoleText("Run commands completed.");
1567 }
1568 delete mesh.cmdchild;
@@ -1572,14 +1571,13 @@ function handleServerCommand(data) {
1571 // Windows Powershell
1572 mesh.cmdchild = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], options);
1573 mesh.cmdchild.descriptorMetadata = 'UserCommandsPowerShell';
1575 - mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
1576 - mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); });
1574 + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); });
1575 + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); });
1576 mesh.cmdchild.stdin.write(data.cmds + '\r\nexit\r\n');
1577 mesh.cmdchild.on('exit', function () {
1578 if (data.reply) {
1579 mesh.SendCommand({ action: 'msg', type: 'runcommands', result: replydata, sessionid: data.sessionid, responseid: data.responseid });
1580 } else {
1582 - sendConsoleText(replydata);
1581 sendConsoleText("Run commands completed.");
1582 }
1583 delete mesh.cmdchild;
@@ -1589,14 +1587,13 @@ function handleServerCommand(data) {
1587 // Linux shell
1588 mesh.cmdchild = require('child_process').execFile('/bin/sh', ['sh'], options);
1589 mesh.cmdchild.descriptorMetadata = 'UserCommandsShell';
1592 - mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); });
1593 - mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); });
1590 + mesh.cmdchild.stdout.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); });
1591 + mesh.cmdchild.stderr.on('data', function (c) { replydata += c.toString(); sendConsoleText(c.toString()); });
1592 mesh.cmdchild.stdin.write(data.cmds.split('\r').join('') + '\nexit\n');
1593 mesh.cmdchild.on('exit', function () {
1594 if (data.reply) {
1595 mesh.SendCommand({ action: 'msg', type: 'runcommands', result: replydata, sessionid: data.sessionid, responseid: data.responseid });
1596 } else {
1599 - sendConsoleText(replydata);
1597 sendConsoleText("Run commands completed.");
1598 }
1599 delete mesh.cmdchild;