Link to home
Start Free TrialLog in
Avatar of Al283
Al283

asked on

CGI script doesn't wait for shell script to be executed

The webpage (index1.html)
<html>
  <body>
    <img src="pic.gif">
    <form action="../cgi-bin/update_pic1.cgi" method="get">
      <input type=submit value="Update Pic">
    </form>
  </body>
</html>

Open in new window

consists of a gif image and a webform, which executes a cgi-script (update_pic1.cgi)
#!/bin/bash                                                                                              
echo "Content-type: text/html"
echo ""
sleep 2
gnuplot plot_pic.gp
echo "<html><body>"
echo "<script>location.href='///localhost/index1.html'</script>"
echo "</body></html>"

Open in new window

which creates a new gif image (by gnuplot).
I have a well-know problem: instead o reloading the gif-image only, I have to reload the whole page since cgi script leaves the original page,  which is not desired.
To circumvent this problem, I split the webpage (index2.html) into 2 frames
<html>
    <frameset rows="90%,*">
      <frame src="main.html">
      <frame src="hidden.html" name="hidden">
    </frameset>

</html>

Open in new window

the one with the pic and the webform (main.html)
<html>
  <head><script>
      function updatePic(){
      var pic=document.getElementById("pic");
      pic.src="pic.gif"
      }
  </script></head>
  <body>
    <img src="pic.gif" id="pic">
    <form action="../cgi-bin/update_pic2.cgi" method="get" target="hidden" onclick="return updatePic()">
      <input type=submit value="Update Pic">
    </form>
  </body>
</html>

Open in new window

and the other one for redirecting the cgi output (hidden.html)
<html>
  <body>
  </body>
</html>

Open in new window

which can be hidden.
This way I don't have to reload  the whole main.html, but just reload the picture only by using onclick javascript function.
The problem is that in this case the javscript function does not wait for the script creating the new pic.gif and redraws the old gif image.
How to force pic.gif on main.html to be renewed only after it is created by the cgi-script, and not before?

I would appreciate a solution without references to Perl and AJAX and not longer than 5 lines of code. Bash, javascript or c++ are preferred. I strongly believe that a simple solution exists.
ASKER CERTIFIED SOLUTION
Avatar of egarciat
egarciat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Al283
Al283

ASKER

Wow! That is exactly what I needed. Thanks! Could you please just clarify why it waits now properly?
pic.src="pic.gif"

will not recreate the image, just fetch the already created one.