Professor
Professor

Reputation: 2154

Is it possible to run a .bat file on button click with node

Is it possible to run bat/executable file using html5 button and nodejs? if yes how do i go about it

Upvotes: 0

Views: 1848

Answers (2)

Professor
Professor

Reputation: 2154

i figured out how to solve my problem

function Process() {
const process = require('child_process');   
var ls = process.spawn('script.bat');
ls.stdout.on('data', function (data) {
  console.log(data);
});
ls.stderr.on('data', function (data) {
  console.log(data);
});
ls.on('close', function (code) {
   if (code == 0)
        console.log('Stop');
   else
        console.log('Start');
});
};

document.getElementById('buttonid').addEventListener('click', function(e)     {
Process();
console.log("working");
});

Upvotes: 1

Dulara Malindu
Dulara Malindu

Reputation: 1637

Is it possible to run an .exe or .bat file on 'onclick' in HTML

I think you can find a serverside solution with above url. it is imposible to do with just pure HTML. because there is a huge security risk.

yes.! what happens if someone run a code like "FORMAT C: or DELETE x:/y/z.s No matter whatever the javascript framework you use. javascript runtime engine is sandboxed. so you can't do anything outside the browser. But if you are using the chrome browser there may be a way of doing that. because chrome browser runs on chrome OS. you'll be able to write a browser plugin which enables you to run batch scripts through it. do some research on it.

Google chrome extension and batch command

you need to do a research on that.!

my openion.... use serverside technology or create a desktop app to run batch scripts. web apps are difficult to use to do general stuff.

Upvotes: 1

Related Questions