Reputation: 13
^Topic
I have Debian 8 now.
I have 2 node files I want run this 2 files together
Program 1 should start nodejs /home/Bots/server/server.js after this I need a timeout from 10 sec. Programm 2 should start after 10 secounds when program 1 started. nodejs /home/Bots/f.js
Thanks
I found here nothing what work :/
Upvotes: 0
Views: 410
Reputation: 707318
I will assume your java
tag should be javascript
since it looks like you're talking about nodejs.
It's a bit hard to tell exactly what you're trying to do, but you can launch new processes from within nodejs using the child process module with either .exec()
or .spawn()
.
So, if you have one nodejs process running already, you can use setTimeout()
and the child process module to launch another process at some future scheduled time.
For example, here's an example from the child_process doc pages wrapped inside a setTimeout()
:
const exec = require('child_process').exec;
setTimeout(function() {
const child = exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
}, 10 * 1000);
Upvotes: 1