How do I run the system commands in javascript?
Please give more information of your environment.
Unprivileged JavaScript in a browser can neither list files nor execute programs for security reasons.
In node.js for example executing programs works like this:
var spawn = require('child_process').spawn,
var ls = spawn('ls', ['-l']);
ls.stdout.on('data', function (data) {
console.log(data);
});
And there is a direct way to list files using readdir()
An even easier way in node.js is:
var fs = require('fs');
var ls = fs.readdirSync('/usr');
The variable ls
now contains an array with the filenames at /usr.
You can't run system commands on the client with JS since it works inside a browser sandbox. You'd need to use some other client side tech like Flash, ActiveX or maybe Applets