CGI script programing assistance needed

59 views Asked by At

I have a script, in the cgi-bin which generates this page. The intent of which is to serve as an interface for a panning web camera I built. The camera, does the pan, then quickly returns to the center position. I figured out that this is because every time the page loads, all the scripts are called, in succession, ending with z.py. How can I fix this program so that the scripts do not run until a selection occurs? As it is, everything runs when the page loads, which is why It always pans back to center.

#! /bin/sh
echo "content-type: text/html"
echo
echo "<!DOCTYPE html><html><head><title>pan camera</title></head>"
echo "<body>"

echo "<form action=\"g.pt1\" method=\"get\">"
echo "<select name=\"letter\" onchange=\"submit();\">"
echo "  <option value=\"w\">w</option>"
echo "  <option value=\"a\">a</option>"
echo "  <option value=\"s\">s</option>"
echo "  <option value=\"d\">d</option>"
echo "  <option value=\"z\">z</option>"
i=0
for i in a s d w z
        do
                echo  " $i  $(./$i.py)"
        done
echo "</select></form>"
echo "<iframe src=\"localhost:8888/?action=stream\" width=\"330\" height=\"260\">"
echo " <p>Your browser does not support iframes.</p>"
echo "</iframe>"
echo "</body></html>"
1

There are 1 answers

0
Dale_Reagan On

Note - not a 'web programmer'...

Is the script above 'everything'? (or just the output?)

Also, for this type of use you might want to consider using a 'here document' to avoid 'escaping' all the quotes.

The FOR LOOP with the echo line in the 'middle' is run 'each time' the page loads.

$(./$i.py) will run, in order, a.py, then s.py, ... and then z.py

Remove the loop and Change this logic to 'get user input' and you should be good to go.