Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i just started exploring perl a few days ago and i modified a guestbook script to my requirements.
all the details from the html form transferred nicely to the logfile i created.
from here, i wanted the values to be used by another script program (as i said, i am very new).
when i inserted the ff lines:

$change = '/usr/local/file.sql'
exec $change or print STDERR "couldn't exec $change: $!";

i got the dreaded http 500 error and when i checked the apache logs, it said that there is a
'premature end of header scripts error'
but when i run the perl on the command line, it executes properly.

please help me guys

Replies are listed 'Best First'.
Re: running a script from perl
by Zaxo (Archbishop) on Nov 13, 2001 at 18:11 UTC
    You want backticks, system, or maybe do FILE. The exec function never returns to the caller.

    After Compline,
    Zaxo

Re: running a script from perl
by trantor (Chaplain) on Nov 13, 2001 at 18:03 UTC

    You probably want to use system, not exec.

    As you can read from perldoc perlfunc, exec never returns: the current process is replaced by the new one. This will cause your original guestbook CGI script to terminate abnormally without completing its task.

    Another comment about file.sql: is it an actual executable (shell, perl, binary, whatever) or a file containing SQL statements only? In the latter case, you most probably need to run an SQL processor passing that file name.

    -- TMTOWTDI

Re: running a script from perl
by frankus (Priest) on Nov 13, 2001 at 18:01 UTC

    I'd suggest this :"perldoc -f exec", if you use Unix.
    Exec doesn't return a value; try system instead. IIRC
    Once you've got it working check out CGI and DBI to port the whole app to Perl.
    It's very nice, there are bound to be good examples of CGI with DBI (Database interface) sitting in CUFP or tutorials

    --

    Brother Frankus.

    ¤

Re: running a script from perl
by ColtsFoot (Chaplain) on Nov 13, 2001 at 18:07 UTC
    I'm not exactly sure what you are trying to do, but you will
    need to output an http header so the web page can be
    displayed. I would suggest using CGI.pm as follows
    #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsTo Browser); my $page = new CGI; print $page->header() print $page->start_html(); ... .. . print $page->end_html();
    Hope this helps, if not post a bit more of your code