View previous topic :: View next topic |
Author |
Message |
canam101 -
Joined: 15 Jan 2007 Posts: 9
|
Posted: Mon Jan 15, 2007 9:17 pm Post subject: Trying to run a simple python script |
|
|
I have been running abyss for some time as a simple server and
would now like to let people fill out a form which would capture
variables and then run a perl (or python) script.
Looking at the help file, I managed to set up the interpreter for
perl and for python.
Since I have zero experience of using a web server this way, I
looked around the forum and found an example of some html which
allows the user to fill out a form, and then calls a 'php' script.
It appears that I can call a perl or python script directly, so I
can ignore 'php' for now, I hope.
Here is a sketch of the html I am playing with:
<body>
<form method="POST" action="time1.py">
<center>First Field:<br>
<input type="text" name="first_field" size="19"><br>
<input type="submit" value="submit" name="submit">
</center>
</body>
So this html is in the htdocs folder and the script, time1.py, is
also in the htdocs folder. The server is running, and I open my
browser, and type in
http://myserver.com/test.html,
and click on the 'submit' button. That runs time1.py.
I know time1.py runs because I can see the result.
However, I get a '500 server error', and when I look at the cgi
log, it shows
CGI: [/usr/bin/python time1.py ] URI: /time1.py Broken pipe
By the way, I tried this with a perl script and get the same
results.
I'm running v 2.3.0.4 of Abyss on a linux system.
Thanks for any help. |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Tue Jan 16, 2007 1:08 pm Post subject: Re: Trying to run a simple python script |
|
|
canam101,
Is Python declared as a scripting language?
Does the .py file have the exectuable bit (x)? If so remove that bit using a command such as:
_________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
|
canam101 -
Joined: 15 Jan 2007 Posts: 9
|
Posted: Tue Jan 16, 2007 3:00 pm Post subject: Re: Trying to run a simple python script |
|
|
aprelium wrote: | canam101,
Is Python declared as a scripting language?
Does the .py file have the exectuable bit (x)? If so remove that bit using a command such as:
|
Thanks. I did that but got the same result - it runs but I also get the 500 server error.
I'm wondering, though, if it isn't something my system doesn't like about running scripts via abyss because when I submitted my question here, it submitted ok, but I also got the 500 server error.
I'll see what happens this time. |
|
Back to top |
|
|
canam101 -
Joined: 15 Jan 2007 Posts: 9
|
Posted: Tue Jan 16, 2007 3:01 pm Post subject: |
|
|
No, it submitted ok this time. |
|
Back to top |
|
|
canam101 -
Joined: 15 Jan 2007 Posts: 9
|
Posted: Tue Jan 16, 2007 6:13 pm Post subject: |
|
|
I finally got something to run and thought I would pass along what
I have for other newcomers.
What I wanted to do was enter a couple of fields on a web page and
have them taken in as arguments by a python script, which then
copied one file to another file, using the names I supplied.
I had previously set up the interpreter for python.
Since I figured I had to use a php module to call the python
module, I also installed php 5 and set up the web server to
recognize it.
The instructions for doing that are in the help section of the
first console screen for the server. Very clearly written too. My
thanks to the authors. I'm not too tecchie and need all the
clarity I can get in instructions.
Here's the bit of html code:
<form method="POST" action="mailer.php">
<br>
<center>From Field(If known):<br>
<input type="text" name="fromfield" size="19"><br>
From Fieeld:<br>
<center>To Field(If known):<br>
<input type="text" name="tofield" size="19"><br>
To Fieeld:<br>
There is also a 'submit' button which isn't shown.
When the submit button is pressed, the html calles mailer.php.
Both the html and the php file are in htdocs.
Here is the php file
<?php
if(isset($_POST['submit'])) {
$fromfield = $_POST['fromfield'];
$tofield = $_POST['tofield'];
$result = exec("/home/joe/abyssws/htdocs/time1.py
$fromfield $tofield");
echo "Thank you for your time.";
echo $fromfield; echo $tofield;
} else {
echo "blarg!";
}
?>
The toughest part of getting this to run was figuring out the
right way to call the python module, time1.py, and in getting the
path to it correct. Also, figuring out how the arguments should be
presented in the exec statement was another trial and error thing.
This seems to provide a clear path from html to exec of the python
module, so, even with this basic functionality, I should be able
to make much better use of the abyss web server.
And I'm not seeing the 500 server error any more. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|