shell 脚本和 jQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5705361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
shell scripting and jQuery
提问by user478636
I want to execute a linux command that returns the currently logged on user in linux.
我想执行一个 linux 命令,该命令返回 linux 中当前登录的用户。
Using jQuery and ajax, passing this command to the PHP, which will receive and execute this command using exec()
function. The value should be stored and returned.
使用 jQuery 和 ajax,将此命令传递给 PHP,PHP 将使用exec()
函数接收并执行此命令。该值应该被存储和返回。
Upon returning, jquery ajax should return it to a contents of a span tag.
返回时,jquery ajax 应将其返回到 span 标记的内容。
How can this be achieved?
如何做到这一点?
回答by Matt Ball
回答by Juanma
This javascript
sample run a tail
command using node.js
此javascript
示例tail
使用以下命令运行命令node.js
#!/usr/bin/env node
var readline = require('readline');
var cp = require('child_process');
var tail = cp.spawn('tail', ['-500', 'mylogfile.log']);
var lineReader = readline.createInterface(tail.stdout, tail.stdin);
lineReader.on('line', function(line) {
console.log('Line: ' + line);
});
tail.on('close', function(code, signal) {
console.log('ls finished...');
});