Modify msg.payload after sending the message

Hi,

I'm using a node to execute a Python script with a spawn process and I'm reading stdout during execution. I would like to see the output in the debug window, which works fine if I send everytime a message when my child.stdout.on() function gets triggered. But I don't want to send for every line a new message, I would like to use it in a way, that I just send one time a message and when more data is coming I just append the already sent message.

My idea is, to write all the output in a context variable and use a setInterval function which is reading that context variable and refreshing the msg.payload. But the content in the debug window doesn't change after refreshing msg.payload, only if I send a new msg I see the updated content.

JS file:

var child = spawn('python3', [node.py_path, node.sys_cfg]);
      child.stdout.on('data', function(data) {
        console.log(data.toString());
        proc_data = globalContext.get("at_arr");
        proc_data += data.toString();
        globalContext.set("at_arr", proc_data);
});

HTML file (proposal which doesn't work currently):

<script type="text/javascript">
  window.setInterval(function() {
    //var globalContext = this.context().global;
    //var data_str = globalContext.get("at_arr");
    //msg.payload = data_str;
    //document.getElementById("msg").innerHTML = msg.payload;
}, 1000);
</script>

Any idea how to modify the msg.payload after sending the msg?

You can't do that. Once the message has been sent you no longer have access to it to update.

You can update the value in context, but to display anything different in the Debug sidebar will require a new message to be send.

If you used an exec node then you could configure it to wait till command completion and then send all the output in one message.