469,268 Members | 920 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

Run a Perl program from an HTML page without user intervention

13
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:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2.  
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  7.  
  8. <title>testing perl script from HTML page</title>
  9. </head>
  10.  
  11. <body>  
  12. <!--#exec "d:/webdocs/www/irm/training/CGI/tipweek.pl" -->
  13. <p>This page is to test to see whether I can run a Perl script from an HTML page.</p>
  14. <p>&nbsp;</p>
  15. <br>
  16. </p><p>Other stuff on the page, including a server-side include below this line.</p>
  17. <p>
  18.   <!--#include file="Tips/currenttip.txt" -->
  19. <br>
  20. </p>
  21. </body>
  22. </html>
  23.  
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!
Aug 30 '07 #1
22 5420
KevinADC
4,059 Expert 2GB
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
Aug 30 '07 #2
owlice
13
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!!
Aug 31 '07 #3
docdiesel
297 Expert 100+
Hi,

try
Expand|Select|Wrap|Line Numbers
  1. <!-- #exec CGi="CGI/tipweek.pl" -->
  2.  
or
Expand|Select|Wrap|Line Numbers
  1. <!-- #exec CMD="D:\webdocs\www\irm\training\CGI\tipweek.pl" -->
  2.  
At least one of them should work. (See also Web Development Developer Center, http://msdn2.microsoft.com/en-us/library/ms525620.aspx .)

Regards, Bernd
Aug 31 '07 #4
KevinADC
4,059 Expert 2GB

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.
Sep 1 '07 #5
owlice
13
Thank you!!

Hi,

try
Expand|Select|Wrap|Line Numbers
  1. <!-- #exec CGi="CGI/tipweek.pl" -->
  2.  
I got "Failed to execute CGI : Win32 Error Code = 3" in response.

or
Expand|Select|Wrap|Line Numbers
  1. <!-- #exec CMD="D:\webdocs\www\irm\training\CGI\tipweek.pl" -->
  2.  
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
Sep 4 '07 #6
owlice
13
And things aren't looking too good for the goat....!
Sep 4 '07 #7
numberwhun
3,503 Expert Mod 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. <body onload="/path/to/perl_script.pl">
  2.  
Just a thought.

Regards,

Jeff
Sep 4 '07 #8
KevinADC
4,059 Expert 2GB
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.
Sep 4 '07 #9
numberwhun
3,503 Expert Mod 2GB
He he, it was worth a shot. I didn't know if it was possible or not. Oh well.

Regards,

Jeff
Sep 4 '07 #10
owlice
13
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!
Sep 4 '07 #11
owlice
13
Okay, I found something that works. I don't believe it, but it does. It's
Expand|Select|Wrap|Line Numbers
  1. <img src="CGI/tipweek.pl" border=0 height=0 width=0>
I found that here a while ago: http://www.webxpertz.net/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.
Sep 4 '07 #12
KevinADC
4,059 Expert 2GB
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.
Sep 4 '07 #13
owlice
13
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...).
Sep 5 '07 #14
KevinADC
4,059 Expert 2GB
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.
Sep 5 '07 #15
owlice
13
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.
Amazingly enough, I don't get a pizza box! I thought I would, but no... the result was simply some extra vertical space, hence my moving the IMG tag to the end of the HTML document, where a little extra vertical space doesn't matter.

I find this positively weird.

SSI is definitely enabled; my test page had another #include in it, and that has always worked. It could be that the "virtual" attribute is indeed disabled on the server, and I'll ask the web guys tomorrow if that's the case; I would imagine that one of them should be able to tell me. (For my test script, #include file="CGI/tipweek.pl" pulled the Perl code itself into the HTML page; #include virtual="CGI/tipweek.pl" didn't work. Yeah, it's gotta be turned off; maybe I can convince someone to turn it on.)

I don't know that I can check the error log; I suspect not, but if you can give me a clue as to how one checks one, I'll give it a shot.

Attach your perl script to a post and if I get a chance I will look at it.
Should be good amusement! (I didn't use "strict," I didn't declare variables, and I know I'll have to do a version 2.0, as I recognize the program could potentially get into an endless loop, but so long as it has what it needs in the data source file, it does what it's supposed to do, so I'm calling it done! :-D )

I'll attach it, but it might take me until Tuesday, as I'm up against a deadline to get this whole rewrite (of my whole site) into production. I'm SO far behind because of my "trivial" little tip of the week app and its numerous opportunities for learning, I'm scrambling for the next few days.

Overall, I've concluded that I probably should have done what I did in Javascript, but I know even less Javascript than Perl. (Actually, ColdFusion might have been the best choice, that and a database, but CF and databases get more oversight than Perl and text files, so...)
Sep 6 '07 #16
owlice
13
So my next question is: should I let the goat off the hook now, or wait until everything's in production? :-D
Sep 6 '07 #17
KevinADC
4,059 Expert 2GB
Your browser might be set to not show the broken image place holder. That would explain the no pizza box affect.

The error log can be checked a number of ways, via a control panel if there is one, via FTP if you can get into the logs folder, via telnet if you can log in that way. Ask your tech support people how.
Sep 6 '07 #18
owlice
13
Oh, I definitely get pizza boxes, and I'm glad for that, as it's a good check for me after I've updated things, am checking them in production, and find I've forgotten to move a new graphics file over.

Thanks for the info on the error log! Will talk to the gurus to see whether I have access.
Sep 6 '07 #19
owlice
13
Now the solution is to have the network guy schedule my Perl script to run every Sunday, rather than invoking it from a web page. That is a better way to handle it, and if something happens that prevents the script from running, I can always run it by putting the URL into my browser. We never did figure out why I cannot invoke this script through a more normal method (rather than the IMG tag).

The Perl code is attached; I had to add the .txt extension to upload it. I know there's the possibility of an endless loop; I'll fix that someday! :-) I also need to add a bit of documentation to the code.

The layout of the source file (tipsource.txt) and two examples are given below.

tipsource.txt structure: wknum|Year|TipTitle|TipDesc|TipURL|TipTech
36|07|Voice Mail Tips: Shortcuts for reviewing voice mail messages|When you are listening to your messages, do you want to fast forward or delete without listening to the full message? You can!|0736.htm|Phone
37|07|Reordering columns in Excel using horizontal sort|Have you ever needed to rearrange the columns in a spreadsheet? Did you Copy and paste the entire column in a new spreadsheet in the order you wanted them? There is an easier way to sort your columns.|0737.htm|Excel
Attached Files
File Type: txt tipweekforposting.pl.txt (16.1 KB, 394 views)
Sep 13 '07 #20
owlice
13
I also need to add a bit of documentation to the code.
And fix some of what's there, and take out a few lines that shouldn't be there, and...

(But the good news is that the goat is now free!)
Sep 14 '07 #21
KevinADC
4,059 Expert 2GB
After a quick glance at the code it looks well commented/documented. But it does look like it could use some improvements. If I get a chance I will give it a closer look and make some recommendations if any are warranted.
Sep 14 '07 #22
owlice
13
Kevin, I posted it to amuse you. ("Kids, don't code like this!" :-D) I'm sure it could stand improvements. I learned only what was absolutely necessary to write it, and no doubt there are things that I'd have coded better/differently/etc. if I knew Perl. I'll probably make just minor changes to it after this, however, and only if I really have to. (I'm not a programmer, nor do I play one on TV.)

I appreciate all your help; you've been a peach! Thanks!
Sep 16 '07 #23

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Pierre-Yves | last post: by
reply views Thread by Kirt Loki Dankmyer | last post: by
5 posts views Thread by Robert Latest | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.