Link to home
Start Free TrialLog in
Avatar of PaulS_III
PaulS_III

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of gripe
gripe

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 PaulS_III
PaulS_III

ASKER

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
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.
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
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.
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
Glad you like it.. I'm sure it will make your job easier.