Question

Exec Format Error when calling an HTML file from a perl cgi script

Asked by: PaulS_III

I have a cgi script that uses some javascript functions to display a popup calendar for choosing dates. Thejavascript calls an HTML file named calendar.html as the base for the calendar. Whenever I click on the icon to open the calendar, the new window opens, but with an Error 500 Internal Server Error. Checking the apache error log I see:

Exec format error: exec of '/v/www/cgi-bin/timesheet/calendar.html' failed.

I know this has something to do with perl not knowing how to open or handle the file, or something like that.

So is it possible to execute/open/display an HTML file from within a perl script, or am I missing something here?

Thanks

Paul

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-11-15 at 06:30:32ID21207024
Tags

exec

,

format

,

error

Topics

CGI Scripting

,

Server Side Includes (SSI)

Participating Experts
1
Points
125
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Unable to exec perl cgi's from url
    Made this worth 250 points since I need an answer soon. I have linux mandrake 6.1 and all i'm trying to do is have a perl cgi execute when I access it from a url. e.g.: http://mywebserver/test.pl I want it to return the html output from that perl script. instead, what i ...
  2. Unable to exec perl cgi's from url
    Made this worth 250 points since I need an answer soon. I have linux mandrake 6.1 and all i'm trying to do is have a perl cgi execute when I access it from a url. e.g.: http://mywebserver/test.pl I want it to return the html output from that perl script. instead, what i ...
  3. Apache + Perl scripts
    I'am new in Linux. I install RedHat 6.0 and Apache 1.3.9 I have some HTML pages wich invoque Perl Scripts. So I put in the cgi-bin directory the Perl Scripts and I try to make them work from Apache. I couldn't.... I would like to know what do I have to change in the httpd.c...
  4. Red Hat/Apache Perl/CGI question
    I have a perl script I'm trying to run on an apache webserver. I've pointed the script to the proper perl location and i can run the script in the folder with the ./scriptname.pl but when i try and call it from a webpage nothing happens. I'm sure it has to do with SSI maybe...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: gripePosted on 2004-11-15 at 06:45:49ID: 12584065

It sounds like you're trying to 'exec()' your HTML file instead of printing it's contents. exec() is for 'executing' other executable programs, such as another perl script. Also, exec() will execute it's argument and -never return-, so the rest of your script will not be completed after a successful exec. If you want to output the contents of the file, you should open() the file and print it's contents, like this:

open my $html, '/v/www/cgi-bin/timesheet/calendar.html' or die $!;
while ( <$html> ) { print; }

You should also consider using a templating module to do this stuff. They are built for your very requirements and have the added bonus of allowing you to include and substitute variables or code blocks within your templates.

Some suggested template modules are:

HTML::Template
Template::Toolkit
Text::Template

Hope that helps.

 

by: PaulS_IIIPosted on 2004-11-15 at 06:53:39ID: 12584143

gripe,
Thanks, that does make sense. Now let me go a few steps farther. Here is the entire perl function I am using to generate this popup calendar:

my $SCRIPT=<<END;
<script language="JavaScript">
var NUM_CENTYEAR = 30;
var BUL_TIMECOMPONENT = false;
var BUL_YEARSCROLL = true;
                                                                                                                         
var calendars = [];
var RE_NUM = /^\-?\d+\$/;
                                                                                                                         
function calendar2(obj_target) {
                                                                                                                         
        this.gen_date = cal_gen_date2;
        this.gen_time = cal_gen_time2;
        this.gen_tsmp = cal_gen_tsmp2;
        this.prs_date = cal_prs_date2;
        this.prs_time = cal_prs_time2;
        this.prs_tsmp = cal_prs_tsmp2;
        this.popup    = cal_popup2;
                                                                                                                         
        if (!obj_target)
                return cal_error("Error calling the calendar: no target control specified");
        if (obj_target.value == null)
                return cal_error("Error calling the calendar: parameter specified is not valid target control");
        this.target = obj_target;
        this.time_comp = BUL_TIMECOMPONENT;
        this.year_scroll = BUL_YEARSCROLL;
                                                                                                                         
        this.id = calendars.length;
        calendars[this.id] = this;
}
                                                                                                                         
function cal_popup2 (str_datetime) {
        this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
        if (!this.dt_current) return;
                                                                                                                         
        var obj_calwindow = window.open(
                'calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
                'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
                ',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
        );
        obj_calwindow.opener = window;
        obj_calwindow.focus();
}
                                                                                                                         
function cal_gen_tsmp2 (dt_datetime) {
        return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}
                                                                                                                         
function cal_gen_date2 (dt_datetime) {
        return (
                (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
                + (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
                + dt_datetime.getFullYear()
        );
}
function cal_gen_time2 (dt_datetime) {
        return (
                (dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
                + (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
                + (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
        );
}
                                                                                                                         
function cal_prs_tsmp2 (str_datetime) {
        if (!str_datetime)
                return (new Date());
                                                                                                                         
        if (RE_NUM.exec(str_datetime))
                return new Date(str_datetime);
                                                                                                                         
        var arr_datetime = str_datetime.split(' ');
        return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}
function cal_prs_date2 (str_date) {
                                                                                                                         
        var arr_date = str_date.split('/');
                                                                                                                         
        if (arr_date.length != 3) return alert ("Invalid date format: '" + str_date + "' Format accepted is dd-mm-yyyy");        if (!arr_date[1]) return alert ("Invalid date format: '" + str_date + "' No day of month value can be found");
        if (!RE_NUM.exec(arr_date[1])) return alert ("Invalid day of month value: '" + arr_date[1] + "' Allowed values are unsigned integers");
        if (!arr_date[0]) return alert ("Invalid date format: '" + str_date + "' No month value can be found");
        if (!RE_NUM.exec(arr_date[0])) return alert ("Invalid month value: '" + arr_date[0] + "' Allowed values are unsigned integers");
        if (!arr_date[2]) return alert ("Invalid date format: '" + str_date + "' No year value can be found");
        if (!RE_NUM.exec(arr_date[2])) return alert ("Invalid year value: '" + arr_date[2] + "' Allowed values are unsigned integers");
                                                                                                                         
        var dt_date = new Date();
        dt_date.setDate(1);
                                                                                                                         
        if (arr_date[0] < 1 || arr_date[0] > 12) return alert ("Invalid month value: '" + arr_date[0] + "' Allowed range is 01-12");
        dt_date.setMonth(arr_date[0]-1);
                                                                                                                         
        if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
        dt_date.setFullYear(arr_date[2]);
                                                                                                                         
        var dt_numdays = new Date(arr_date[2], arr_date[0], 0);
        dt_date.setDate(arr_date[1]);
        if (dt_date.getMonth() != (arr_date[0]-1)) return alert ("Invalid day of month value: '" + arr_date[1] + "' Allowed range is 01-"+dt_numdays.getDate()+"");
                                                                                                                         
        return (dt_date)
}
                                                                                                                         
function cal_prs_time2 (str_time, dt_date) {
                                                                                                                         
        if (!dt_date) return null;
        var arr_time = String(str_time ? str_time : '').split(':');
                                                                                                                         
        if (!arr_time[0]) dt_date.setHours(0);
        else if (RE_NUM.exec(arr_time[0]))
                if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
                else return cal_error ("Invalid hours value: '" + arr_time[0] + "' Allowed range is 00-23");
        else return cal_error ("Invalid hours value: '" + arr_time[0] + "' Allowed values are unsigned integers");
                                                                                                                         
        if (!arr_time[1]) dt_date.setMinutes(0);
        else if (RE_NUM.exec(arr_time[1]))
                if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
                else return cal_error ("Invalid minutes value: '" + arr_time[1] + "' Allowed range is 00-59");
        else return cal_error ("Invalid minutes value: '" + arr_time[1] + "' Allowed values are unsigned integers");
                                                                                                                         
        if (!arr_time[2]) dt_date.setSeconds(0);
        else if (RE_NUM.exec(arr_time[2]))
                if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
                else return cal_error ("Invalid seconds value: '" + arr_time[2] + "' Allowed range is 00-59");
        else return cal_error ("Invalid seconds value: '" + arr_time[2] + "' Allowed values are unsigned integers");
                                                                                                                         
        dt_date.setMilliseconds(0);
        return dt_date;
}
                                                                                                                         
function cal_error (str_message) {
        alert (str_message);
        return null;
}
</script>
                                                                                                                         
<form name=tstest>
<input type="Text" name="input5" value="">
<a href="javascript:cal5.popup();"><img src="/image/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
</form>
                                                                                                                         
<script language="JavaScript">
                                                                                                                         
var cal5 = new calendar2(document.forms['tstest'].elements['input5']);
cal5.year_scroll = true;
                                                                                                                         
cal5.time_comp = false;
                                                                                                                         
</script>
END
                                                                                                                         
print $SCRIPT;
}

This is the entire function I am using to generate my page and includes the javascript to generate the popup. So are you saying I can use one of the templating modules to do all of this somehow?

If so could you provide some direction on how I can do this? For one reason or another I am a bit gun shy towards the template modules.

Thanks

 

by: gripePosted on 2004-11-15 at 07:41:54ID: 12584621

I'm not sure what you're using perl for in this case, you seem to be just storing some static javascript into a variable and printing. Is this meant to be output within a larger CGI program or HTML file output? Am I missing something?

The thing with a template module is that it will allow you to separate your logic from your presentation. It often requires a different outlook on the overall design of your solution and layout of your site, but generally results in an easier to manage total package. The templating module will not automatically make everything better for you, but will enable you to store reusable pieces of presentation logic (IE: HTML/JavaScript/XML/etc) in standalone files that you can then include within your CGI (or mod_perl, etc) code to be used them as 'building blocks' to your overall design.

By doing this, you can seperate out your server side logic from your client side logic/presentation and reuse stuff (such as your javascript calendar app above) by embedding it wherever it's needed. This will also ensure that there is only one 'master' file to change to make presentation changes that will then be populated across your templated site as opposed to making many smaller configuration changes for every script with embedded presentation logic or HTML file in general.

I hope this is understandable. It may be the case that you don't require templating, but speaking from personal experience I just find it considerably easier to manage everything through templates. Let me know if you have any questions. In a lot of cases, some of the larger templating modules can also be overkill, such as Template::Toolkit. I would start small with 'Text::Template' and work up to it's limitations before going for the kitchen sink.

 

by: PaulS_IIIPosted on 2004-11-15 at 07:50:47ID: 12584729

Yes this is part of a larger CGI application. I am writing a time tracking application where users can log in, add line items to tasks they are working on, and then print off an excel spreadsheet of they tasks they have been working on within some time frame. Enter this particular situation. I am adding ni this popup calendar to aide the users in picking a dtae range they wish to print off.

I think the light bulb lit up in my brain. I am now taking the HTML code for the text box and such and throwing that off into a template file to open and use using HTML::Template. Therefore my template file will look something like this:

<script language="JavaScript" src="calendar2.js>
</script>
                                                                                                                         
<form name=tstest>
<input type="Text" name="input5" value="">
<a href="javascript:cal5.popup();"><img src="/image/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
</form>
                                                                                                                         
<script language="JavaScript">
                                                                                                                         
var cal5 = new calendar2(document.forms['tstest'].elements['input5']);
cal5.year_scroll = true;
                                                                                                                         
cal5.time_comp = false;
                                                                                                                         
</script>

Then I can use HTML::Template to open and display this file. I am thinking this should work. My only thought/concern would be returning the date picked, but I will experiment with the template variables to try and get that value back.

Please allow me to experiment with this a bit before I award the points and close, but I think you have put me on the right track.

I will be very glad to look at any additional tips/information you are willing to pass on regarding this new approach.

Thanks

Paul

 

by: gripePosted on 2004-11-15 at 08:23:11ID: 12585128

Your form variables will be passed as before. So if you're using CGI.pm, you can do all of your form processing before choosing a template to output. HTML::Template will have no impact on how you normally process your form data.

 

by: PaulS_IIIPosted on 2004-11-15 at 09:09:39ID: 12585608

After some juggling some files around and getting things in the proper place, I got this to work. Thanks for pointing me to the template modules. This is super slick

 

by: gripePosted on 2004-11-15 at 10:08:35ID: 12586165

Glad you like it.. I'm sure it will make your job easier.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...