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