Reputation: 394
We are building an application in node js with electron. There is another software which is installed in all other machines.Now in my node js application i want to launch those software on there respective machines.Is it Possible?
Upvotes: 0
Views: 1408
Reputation: 394
Below code worked as charm for me.
var cmd = require('node-cmd');
cmd.get('WMIC /node:"ABC-XXXXXXX" process call create "C:\\Setup\\app7.exe"',function(err, data, stderr){
console.log('err:', err)
console.log('stderr:', stderr)
})
Remote machine name : ABC-XXXXXXX
Path of exe on remote machine: C:\Setup\app7.exe
Upvotes: 0
Reputation: 4501
You could do this via commands and a child process via spawn. See ▶NodeJs API Docs
const { spawn } = require('child_process');
const bat = spawn('cmd.exe', ['/c', 'my.bat']);
bat.stdout.on('data', (data) => {
console.log(data.toString());
});
bat.stderr.on('data', (data) => {
console.log(data.toString());
});
bat.on('exit', (code) => {
console.log(`Child exited with code ${code}`);
});
const { spawn } = require('child_process');
const ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
Upvotes: 2