fs.readFile('./db.json', function(err, data) {
let json = JSON.parse(data);
for (const i of json) {
if(i.filter == undefined) {
return;
} else {
exec('python', ['main.py', ${i.filter}, ${i.channel}, ${i.price}, ]);
console.log('started')
}
}
})
setInterval(() => {
searchDb();
}, 1000)
请至少花点时间创建一个更详细的问题。 这是你的答案。
const fs = require('fs');
const { exec } = require('child_process');
function searchDb() {
fs.readFile('./db.json', function(err, data) {
if (err) {
console.error('Error reading file:', err);
return;
}
let json = JSON.parse(data);
for (const i of json) {
if (i.filter === undefined) {
continue;
} else {
exec(`python main.py ${i.filter} ${i.channel} ${i.price}`, (error, stdout, stderr) => {
if (error) {
console.error(`Execution error: ${error}`);
return;
}
console.log(stdout);
});
console.log('started');
}
}
});
}
setInterval(() => {
searchDb();
}, 1000);