0
我試圖從一個網頁執行一個Linux命令與node.js,socket.io和(我認爲...)PHP。我看過this YouTube video,我想做同樣的事情,但我不知道如何。Raspberry Node.js&執行命令
你能舉個例子嗎?
我試圖從一個網頁執行一個Linux命令與node.js,socket.io和(我認爲...)PHP。我看過this YouTube video,我想做同樣的事情,但我不知道如何。Raspberry Node.js&執行命令
你能舉個例子嗎?
鏈接到他們的實施可在GitHub庫中鏈接視頻 - mirceageorgescu/raspi-tank。
node.js完全可以運行程序。草案可能如下所示。
服務器
var exec = require('child_process').exec;
io.sockets.on('connection', function(socket) {
socket.on('exec', function(cmd) {
exec(cmd, function(err, stdout, stderr) {
// do something with the output or not
});
});
});
客戶
socket.emit('exec', 'cat file.txt');
關於如何啓動服務器上的插座或從客戶端連接到它的信息可以從socket.io。