Running Python scripts from HTML button

牧云@^-^@ 提交于 2019-12-02 12:38:17

问题


P am trying to implement a button that will run a Python script forward.py (move my robot forward) using Lighttpd web server/PHP 7.0.

The Python script works perfectly when executed in the terminal window however when I try to run it from the click of the button it does not work.

Here is my basic HTML code to execute the .py script:

<html><body>
<h1> Development of Internet controlled robot </h1>
<input type="button" name="forwardbutton" value=" Move forward "onClick="<? exec(' python /var/www/html/forward.py'); ?>">
</body></html>

I have changed the owner of the forward.py script to be www-data however this has made no difference.

I am quite new to working with Raspberry Pis.


回答1:


I am not sure you can open php tags inside onClick event. You should call javascript function maybe and use ajax (to avoid refresh) to call the php page which will have the exec(python program) function.

take a look here Execute PHP function with onClick



来源:https://stackoverflow.com/questions/47894506/running-python-scripts-from-html-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!