Real Time Output - Scripts

Topics about the Software of Revolution Pi
Post Reply
CatBrown
Posts: 3
Joined: 15 Jan 2024, 12:03

Real Time Output - Scripts

Post by CatBrown »

Trying to upload the 'piTest - R Input_Word_1' function inside a script (node.js)

However there is a delay in outputting the data. The function works, however output the data in 'chunks' after around 45 seconds.
How do we remove this delay for real time output via a script?

Code: Select all

const { execFile } = require('child_process');

// Command and arguments
const command = 'piTest';
const args = ['-r', 'Input_Word_1'];

// Function to start the command
function startCommand() 
{
  const piTestProcess = spawn(command, args, { stdio: 'pipe' });

  // Listen for data from the command
  piTestProcess.stdout.on('data', (data) => 
  {
    console.log(`stdout: ${data}`);
  });

  piTestProcess.stderr.on('data', (data) => 
  {
    console.error(`stderr: ${data}`);
  });

  piTestProcess.on('error', (error) => 
  {
    console.error(`Error: ${error.message}`);
  });

  piTestProcess.on('close', (code) => 
  {
    console.log(`Pytest process exited with code ${code}`);
    // Restart the command after it exits
    setTimeout(startCommand, 5000); // Adjust the delay (in milliseconds) before restarting
  });
}

// Start the command initially
startCommand();
Thanks,
Cat
User avatar
nicolaiB
KUNBUS
Posts: 931
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Real Time Output - Scripts

Post by nicolaiB »

You get call piTest with `-1` and it will return asap the value has been printed. I guess the ~45 secs are result of your timer
Post Reply