Daz*_*ylz 6 node.js raspberry-pi
我现在在Raspberry Pi上运行Raspbian,我想为它制作一个控制面板,所以我可以在网络浏览器中控制我的Raspberry Pi.但是如何在NodeJS中执行命令?
您可以使用此node.js代码在树莓派上运行命令(以下是在树莓派上执行重启命令的示例)
var exec = require('child_process').exec;
function execute(command, callback) {
var cmd = exec(command, function(error, stdout, stderr) {
console.log("error: " + error);
callback(stdout);
});
}
function reStart() {
try {
console.log("Reboot");
execute('sudo reboot', function(callback) {
});
}
catch (err) {
console.log(err);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
940 次 |
| 最近记录: |