Real Time Output - Scripts
Posted: 31 Jan 2024, 11:06
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?
Thanks,
Cat
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();
Cat