任何人都可以提供一个在单击按钮时在后台运行系统命令的简单示例。
例如:点击时:
<button onclick="startprocess">Start</button>
运行
$var = system('tail -f /mail.log > /download/mail.log 2>&1 & echo $!');
由于
答案 0 :(得分:4)
html:
<button id="run_system">Start</button>
js:
$('#run_system').on('click', function() {
$.ajax({
url : 'run.php'
}).done(function(data) {
console.log(data);
});
});
run.php:
<?php
echo shell_exec('tail -f /mail.log > /download/mail.log 2>&1 & echo $!');
?>
答案 1 :(得分:0)
向我们提供有关您环境的更多详细信息。 你也可以看看这个。这可能有所帮助。 http://www.sitepoint.com/take-command-ajax/
答案 2 :(得分:0)
你可以试试这个。在index.php中,对命令页面进行ajax调用。它会执行它并返回响应。
的index.php
<script>
function startprocess()
{
jQuery.ajax({
type:'post',
url:'command.php',
data:[],
dataType:'json',
success: function(rs)
{}
failure : function(rs)
{}
});
}
</script>
<button onclick="startprocess();">Start</button>
command.php
system('tail -f /mail.log > /download/mail.log 2>&1 & echo $!');