How do I run the system commands in javascript?

后端 未结 5 819
执念已碎
执念已碎 2020-12-06 06:08

I need to list all the files in the javascript such as \"ls\"??

5条回答
  •  长情又很酷
    2020-12-06 06:38

    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()

提交回复
热议问题