Jquery Button OnClick Run System Command
11,050
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 $!');
?>
Related videos on Youtube
Author by
JeffVader
Updated on June 04, 2022Comments
-
JeffVader almost 2 years
Can anyone provide a simple example of running a system command in the background when a button is clicked.
eg: when this is clicked:
<button onclick="startprocess">Start</button>
run
$var = system('tail -f /mail.log > /download/mail.log 2>&1 & echo $!');
Thanks
-
adeneo almost 11 yearsI'm guessing the example would involve an ajax call and running the command with PHP. You should probably try to figure it out yourself, it's not that hard, and then ask again when and if you fail.
-
-
JeffVader almost 11 yearsThanks. Once the run.php has been called can I get the pid of the tail process it's called ? My original example wrote the pid to $var.
-
adeneo almost 11 yearsAnd now it's echoing the PID back and console logging it ?