Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

node 怎么调用shell,可以做一个web shell吗?

想做一个后台,页面里有个按钮,点这个按钮,就能执行规定好的shell脚本,然后能在页面打印控制台的信息!麻烦了解的告知需要那些东西或相关资料(自己用,简单点就可以了),谢谢了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
const EXEC = require('child_process').execSync;
const SPAWN = require('child_process').spawn;
const RL = require('readline');

使用这三个东东 + express,基本能能实现
比如:

var fnlist = ["1.bz2"];
var rl = RL.createInterface({
    input: SPAWN('bzcat', fnlist).stdout,
    output: process.stdout,
    terminal: false
});

然后你

rl.on('line', function(line){
    //我得到了shell的一行输出
}).on('close', function(){
    //shell完成啦
});

注意很多都是异步的,以及node进程本身的权限、安全问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[5] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...