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.
Al283Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

egarciatCommented:
Try this...

index1.html

<html>
  <body>
    <img src="http://localhost/update_pic1.cgi">
    <form action="index1.html" method="get">
      <input type=submit value="Update Pic">
    </form>
  </body>
</html>

Open in new window


update_pic1.cgi
#!/bin/bash                                                                                              
echo "Content-type: image/gif"
echo ""
gnuplot plot_pic.gp
#Just in case not sure if really needed
#sleep 2
cat ./pic.gif

Open in new window


Since you do not want a better aproach to solve your question I am adhearing to your requirements. Your scripts need better error handling but this will give you a better idea.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Al283Author Commented:
Wow! That is exactly what I needed. Thanks! Could you please just clarify why it waits now properly?
0
egarciatCommented:
pic.src="pic.gif"

will not recreate the image, just fetch the already created one.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.