473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Button to execute python script

Hi

I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...

Thanks

Feb 1 '07 #1
3 11607
On Thu, 01 Feb 2007 11:34:07 -0800, elrondrules wrote:
I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...
No. PHP is a server-side scripting language.

You need to use a client-side scripting language like JavaScript.
Feb 1 '07 #2
"Ivan Marsh" <an*****@you.nowwrote in message
news:pa****************************@you.now...
On Thu, 01 Feb 2007 11:34:07 -0800, elrondrules wrote:
>I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...

No. PHP is a server-side scripting language.

You need to use a client-side scripting language like JavaScript.
I don't think Ivan understood correctly, because it most certainly can be
done with php at the server. Just call the python script via exec() or
system() in the form handler, once you've detected that the button was
clicked.

<form action="execute_python.php" method="post">
<input type="submit" name="submit1" />
</form>

<form action="execute_python.php" method="post">
checkboxeses:
<input type="checkbox" name="foo1" />
<input type="checkbox" name="foo2" />
<input type="checkbox" name="foo3" />
<input type="checkbox" name="foo4" />
<input type="submit" name="submit2" />
</form>

execute_python.php should be something like

<?php
if(isset($_POST['submit1'])){
exec('/path/to/the/python/script/my_python.py');
}
if(isset($_POST['submit2'])){
exec('/path/to/the/python/script/my_other_python.py');
}
?>

Read more about command line and php:
http://fi2.php.net/manual/en/ref.exec.php

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 2 '07 #3
el*********@gmail.com wrote:
Hi

I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...

Thanks
Yes, as Kimmo mentioned you could just exec to a server-side Python
script, but one wonders, since you're going back to the server anyway,
why you're switching languages...

(Just to be clear, here, Ivan is also right: You can't "run" Python in
the browser as it is a server-side language, and the form is living in
the browser, i.e., the client. For the Python script to run, that
information has to be transmitted from the client back to the server, so
the server knows to run the Python code...)
Feb 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fred | last post by:
I have read and tried every combination for hours. I'm sorry, but I don't get it. How do I have a form with textboxes and buttons and allow click events to execute a server function then display...
7
by: spec | last post by:
Hi all, I know nothing about Python. What I need to do is to get a Python script to execute a local shell script. I do not need any output. What would be th eeasiest way to accomplish this? ...
5
by: Chandra | last post by:
Hi, Is there a way to execute a python script(file) in ASP.NET application (programmatically)?? Regards, Chandra
17
by: somialis | last post by:
I have a test environment in python. it is executed by the following command on the command prompt. 1) First i have to go to the dir where the .py file is 2) then i simply execute python...
5
by: johnny | last post by:
Anyone know how I can make Machine A python script execute a python script on Machine B ?
4
by: brad | last post by:
When I use idle or a shell to execute a python script, the script executes in the directory it is currently in (in this case, my desktop). However, when using GNOME and right clicking the py script...
3
by: joe jacob | last post by:
I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added <Directory...
0
by: srinivasan srinivas | last post by:
This is ok. Is there any other way to find it out? Thanks, Srini ----- Original Message ---- From: Gerhard Häring <gh@ghaering.de> To: python-list@python.org Sent: Friday, 20 June, 2008...
1
by: frankvw | last post by:
Hi, Sorry if this is an obvious question but I am new to python and can't seem to find an easy example for what I want to to. I would like to define a button with tinker and then have that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.