运行带有 html 按钮的 shell 脚本 [英] Run a shell script with an html button

查看:77
本文介绍了运行带有 html 按钮的 shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网站上按下按钮时启动 bash 脚本.这是我的第一次尝试:

I want to launch a bash script when a button is pressed on a website. This is my first attempt:

<button type="button" onclick="/path/to/name.sh">Click Me!</button>

但没有运气.有什么建议吗?

But no luck. Any suggestions?

推荐答案

正如 Luke 所说,您需要使用服务器端语言,例如 php.这是一个非常简单的 php 示例:

As stated by Luke you need to use a server side language, like php. This is a really simple php example:

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("/path/to/name.sh");
}
?>

<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<a href="?run=true">Click Me!</a>

将其另存为 myfilename.php 并将其放置在装有 php 的 Web 服务器的机器上.同样的事情可以用 asp、java、ruby、python 来完成……

Save this as myfilename.php and place it on a machine with a web server with php installed. The same thing can be accomplished with asp, java, ruby, python, ...

这篇关于运行带有 html 按钮的 shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆