html button to call php shell_exec command

2019-05-11 07:10发布

问题:

I have google the heck out of this an I cannot get an answer to this. I hate php, but out php guy is too busy and I need HELP!

I want to call a perl script from an html button. But, I just want it to run in the back ground, I don't need to display anything from it... Would something like this work?

<html>
<body>
    <p>
        <button onclick=<?php exec('test.pl') ?>Run Perl</button>
    </p>
</body>

I would prefer not to use cgi, I want to keep this as simple as possible.

Thanks

回答1:

That will not works, you have to create an action for that:

<?php
    if (isset($_POST['button']))
    {
         exec('test.pl');
    }
?>
<html>
<body>
    <form method="post">
    <p>
        <button name="button">Run Perl</button>
    </p>
    </form>
</body>


回答2:

Looks like you are trying to call PHP with a JavaScript action. This will not work. You can try submitting a form and executing the PHP code when the form is submitted, like:

<?php if (isset($_POST['button'])) { exec('test.pl'); } ?>
<form action="" method="post">
    <button type="submit" name="button">Run Perl</button>
</form>


回答3:

Addressing the 'run in background' part of this problem, you should be able to put an & at the end to force it to the background.

So exec('test.pl &');



标签: php html shell