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 $!');
?>
Share:
11,050

Related videos on Youtube

JeffVader
Author by

JeffVader

Updated on June 04, 2022

Comments

  • JeffVader
    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
      adeneo almost 11 years
      I'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
    JeffVader almost 11 years
    Thanks. 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
    adeneo almost 11 years
    And now it's echoing the PID back and console logging it ?