如何在javascript中运行系统命令? [英] How do I run the system commands in javascript?
本文介绍了如何在javascript中运行系统命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要列出javascript中的所有文件,例如ls??
I need to list all the files in the javascript such as "ls"??
推荐答案
请提供更多信息你的环境。
Please give more information of your environment.
出于安全原因,浏览器中的非特权JavaScript既不能列出文件也不能执行程序。
Unprivileged JavaScript in a browser can neither list files nor execute programs for security reasons.
在node.js中,例如执行程序的工作原理如下:
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);
});
使用 readdir()
这篇关于如何在javascript中运行系统命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文