Run a Perl program from an HTML page without user intervention

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • owlice
    New Member
    • Aug 2007
    • 13

    Run a Perl program from an HTML page without user intervention

    Greetings!

    I thought I'd add a little something to a web site, a "tip of the week," and wanted it automated so that if I get hit by a truck (or, more likely, am forgetful), the tip is updated automatically.

    I learned enough Perl (read: just enough) to code a script that does what I want it to do. Now the question is: how to get it to run automatically.

    I would like the program to be invoked when someone, anyone, hits my homepage. I know little about our environment -- I'm not a developer -- but know that I'm on a Windows box and that we're running IIS. Server-side includes work. Perl for use with forms works. Beyond that, I must offer my apologies for my cluelessness.

    I've tried to use the #exec command on my HTML page to invoke the Perl script. Doesn't work. Here's the HTML to my test page:

    [code=html]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>testin g perl script from HTML page</title>
    </head>

    <body>
    <!--#exec "d:/webdocs/www/irm/training/CGI/tipweek.pl" -->
    <p>This page is to test to see whether I can run a Perl script from an HTML page.</p>
    <p>&nbsp;</p>
    <br>
    </p><p>Other stuff on the page, including a server-side include below this line.</p>
    <p>
    <!--#include file="Tips/currenttip.txt" -->
    <br>
    </p>
    </body>
    </html>
    [/code]

    I do not get an error message, but the files that are supposed to be updated are not updated, so something isn't happening that should be happening.

    If I enter the URL for the Perl script into my browser, the script runs; the files are updated.

    I don't want the Perl script to create my homepage, as I'm not the only one who needs to be able to edit the page.

    Is there some relatively painless way to invoke a Perl script (which doesn't use user input and doesn't need to return anything to the page) from an HTML page?

    TIA!
    Last edited by numberwhun; Aug 31 '07, 10:49 PM. Reason: Add code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    use the virtual SSI tag instead of exec and you need to use the relative url to the script, not an internal machine path:

    <!--#include virtual="../CGI/tipweek.pl" -->

    see how that works

    Comment

    • owlice
      New Member
      • Aug 2007
      • 13

      #3
      Thanks! I tried that, and get "Error processing SSI file."

      I also tried <!-- #exec virtual="CGI/tipweek.pl" -->, which gives me "Invalid SSI Tag."

      And "<!-- #exec "CGI/tipweek.pl" -->", which doesn't give me an error message, but also doesn't update the files.

      This latter made me think it might be a files permissions problem, as I've had that problem before (a Perl script apparently running, but no changes appearing in the file that should be changed), so I wrote a little test script to write to the files, and that worked, so the permissions are fine.

      I'm open to suggestions! Heck, at this point, I'm desperate for suggestions! I'm at the point where I'm ready to burn black candles and sacrifice a goat, even! Oy!!

      Comment

      • docdiesel
        Recognized Expert Contributor
        • Aug 2007
        • 297

        #4
        Hi,

        try
        [code=html]
        <!-- #exec CGi="CGI/tipweek.pl" -->
        [/code]
        or
        [code=html]
        <!-- #exec CMD="D:\webdocs\www \irm\training\C GI\tipweek.pl" -->
        [/code]

        At least one of them should work. (See also Web Development Developer Center, http://msdn2.microsoft.com/en-us/library/ms525620.aspx .)

        Regards, Bernd
        Last edited by numberwhun; Aug 31 '07, 10:48 PM. Reason: Add code tags

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by owlice

          I'm open to suggestions!
          Check the server errror log and see if there is anything related to the script you are trying to run via the SSI tags. Probably not but it's worth a look. Post the script here if it's not too long or attach it to a post.

          Comment

          • owlice
            New Member
            • Aug 2007
            • 13

            #6
            Thank you!!

            Originally posted by docdiesel
            Hi,

            try
            [code=html]
            <!-- #exec CGi="CGI/tipweek.pl" -->
            [/code]
            I got "Failed to execute CGI : Win32 Error Code = 3" in response.

            or
            [code=html]
            <!-- #exec CMD="D:\webdocs\www \irm\training\C GI\tipweek.pl" -->
            [/code]
            And for this, I got "The CMD option is not enabled for #EXEC calls" in response.

            That banging you hear is my head against my desk!

            The good thing is that the script DOES run when I enter the URL for it into the browser location. At least I have that!

            I don't even know who to talk to here about this, but I guess I'm about to find out! :-D

            Comment

            • owlice
              New Member
              • Aug 2007
              • 13

              #7
              And things aren't looking too good for the goat....!

              Comment

              • numberwhun
                Recognized Expert Moderator Specialist
                • May 2007
                • 3467

                #8
                Originally posted by owlice
                I got "Failed to execute CGI : Win32 Error Code = 3" in response.
                This is just a complete shot in the dark, but have you tried adding the onload="" option to your body tag in your HTML and specifying your Perl script after the equals sign in the double quotes?

                ie:
                [code=html]
                <body onload="/path/to/perl_script.pl" >
                [/code]

                Just a thought.

                Regards,

                Jeff

                Comment

                • KevinADC
                  Recognized Expert Specialist
                  • Jan 2007
                  • 4092

                  #9
                  hehehe.... good try. That would be for javascript. The browser would have no clue what to do with perl code.

                  The OP just needs to hit on the correct SSI tag and the correct path to his perl code to get it working.

                  Comment

                  • numberwhun
                    Recognized Expert Moderator Specialist
                    • May 2007
                    • 3467

                    #10
                    He he, it was worth a shot. I didn't know if it was possible or not. Oh well.

                    Regards,

                    Jeff

                    Comment

                    • owlice
                      New Member
                      • Aug 2007
                      • 13

                      #11
                      Heh! Jeff, I've probably tried that; I've tried many many things.

                      Kevin, not that it matters much (well, I suppose it does to some, but not to anyone here!), that'd be her Perl script. :-)

                      I'd post the script (or rather, attach it, because it's a little long) if I thought that would help, but I know the script works, so I don't think that's the problem. I think you're right in thinking I just need the right tag or SOMEthing. The error is in the HTML page, not in the script.

                      I'm sure the script would amuse the real Perl programmers here, however, so there might be a comic value in posting it!

                      Comment

                      • owlice
                        New Member
                        • Aug 2007
                        • 13

                        #12
                        Okay, I found something that works. I don't believe it, but it does. It's
                        Code:
                        <img src="CGI/tipweek.pl" border=0 height=0 width=0>
                        I found that here a while ago: http://www.webxpertz.n et/forums/archive/index.php/t-710.html

                        It hadn't worked for me before, but perhaps it was because I hadn't tested it the same way I'm testing now (read: not quite as well).

                        SO weird!

                        Thank you for your help, gentlemen; I really appreciate it, and if I find the right way to do this, I'll post that as well.

                        Comment

                        • KevinADC
                          Recognized Expert Specialist
                          • Jan 2007
                          • 4092

                          #13
                          That can work but the perl script should be returning an image, not text. This is the SSI tag you want to use:

                          <!--#include virtual="../CGI/tipweek.pl" -->

                          you just need to get the "../CGI/tipweek.pl" part correct for it to work.

                          Comment

                          • owlice
                            New Member
                            • Aug 2007
                            • 13

                            #14
                            Thanks, Kevin!

                            The Perl program doesn't return anything to the web page, nor is it supposed to; it simply checks info and updates files if they need updating.

                            Putting the IMG tag at the bottom of the HTML code works well; put somewhere else, I get a little empty space on the page. The first time the browser hits the page, the #include file=Tips/currenttip.txt still displays with the previous week's info (as it should, as the Perl script hasn't updated it yet), but the second hit/refresh shows the update, and that's fine.

                            I tried every variation of the path (logical to riduculous, this-can't-possibly-work variations) for the #include virtual=..., and none of them worked. The file was found at the path cgi/tipweek.pl when I used #include file="cgi/tipweek.pl" (which pulls all the code into the HTML page), but then changing "file" to "virtual".. . didn't work. And the file is found at cgi/tipweek.pl for the img source.

                            At this point, I have to think that some setting on the server is causing the problem. I've sent this on to our system gurus. They know I've found something that works, but I'm hoping they will look into this to give me a more fitting solution. (Maybe they'll turn on CMD so that #exec cmd works? I can hope!)

                            'Tis a puzzlement, but at least it appears I can put this into production on Monday as I'd hoped (assuming I finish everything else I've had to neglect while I worked on this one little bit...).

                            Comment

                            • KevinADC
                              Recognized Expert Specialist
                              • Jan 2007
                              • 4092

                              #15
                              if this works in the image tag: CGI/tipweek.pl it should work in the SSI tag unless SSI is disabled or the "virtual" tag is disabled. But even though your perl script only updates files it still has to return an appropriate MIME header back to the calling page otherwise it will retun a 500 internal server error. If you are using the image tag to call the script you will not see the error as the image tag expects an image file with an image header, but it will return a broken image symbol or as we used to call them a pizza box, the little square with the "x" in it. I would check the error log and see if it is not filling up with errors/warnings related to calling the perl script.

                              Attach your perl script to a post and if I get a chance I will look at it.

                              Comment

                              Working...