php html按钮调用php shell_exec命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7540847/
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
html button to call php shell_exec command
提问by JonnyCplusplus
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!
我已经谷歌了,我无法得到答案。我讨厌 php,但是 php 的人太忙了,我需要帮助!
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 按钮调用 perl 脚本。但是,我只是想让它在后台运行,我不需要从中显示任何内容......这样的东西会起作用吗?
<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.
我不想使用 cgi,我想让它尽可能简单。
Thanks
谢谢
回答by tttony
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>
回答by Rusty Fausak
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:
看起来您正在尝试使用 JavaScript 操作调用 PHP。这是行不通的。您可以尝试提交表单并在提交表单时执行 PHP 代码,例如:
<?php if (isset($_POST['button'])) { exec('test.pl'); } ?>
<form action="" method="post">
<button type="submit" name="button">Run Perl</button>
</form>
回答by nick
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 &');
所以 exec('test.pl &');