Help

Discussion in 'Perl Misc' started by Rob, Nov 15, 2003.

  1. Rob

    Rob Guest

    I have a small CGI script that attempts to create a file on the fly.
    The script runs successfully from the command prompt. Although when I
    execute in a browser the file does not get created and therefore the
    contents are not displayed on the page. I have try several different
    approaches all have fialed to correct this issue. I have checked the
    promissions, I am login in under the httpd userid, I have checked the
    rc on the system command(see below), and have hit the wall.

    HERE IS THE SCRIPT:
    ****************************************************************************
    #!/usr/bin/perl -w
    use strict;
    use CGI ':standard';

    my @fcetabs;
    my @tablist;
    my $dbin=param('database');

    system("./list $dbin _ list.$$") || print "Bad Return Code from system
    call: $?\n";
    open(FCELST, "list.$$") || print "Database $dbin is currently
    unavailable: $!";

    while(<FCELST>){
    @fcetabs=split;
    push @tablist, $fcetabs[0];
    }
    close(FCELST);
    system("rm ./list.$$");

    print header;
    print start_html('Table Selection');
    showtabs(@tablist);
    print end_html;

    sub showtabs {
    print start_form(-name=>'lstfield'),
    h2('Please select a table for list of fields:'),
    radio_group(-name=>'tables',-values=>[@_]),
    p(),
    submit(-name=>'lflds',-label=>'List Fields'),
    end_form;
    }

    HERE IS THE OUTPUT FROM THE COMMAND LINE:
    ****************************************************************************
    /cgi-bin> listfce.cgi database=sample
    Bad Return Code from system call: 0
    Content-Type: text/html

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <HTML><HEAD><TITLE>Table Selection</TITLE>
    </HEAD><BODY><FORM METHOD="POST"
    ENCTYPE="application/x-www-form-urlencoded" NAME="lstfield">
    <H2>Please select a table for list of fields:</H2><INPUT TYPE="radio"
    NAME="tables" VALUE="cust_items" CHECKED>cust_items<INPUT TYPE="radio"
    NAME="tables" VALUE="customers">customers<INPUT TYPE="radio"
    NAME="tables" VALUE="households">households<INPUT TYPE="radio"
    NAME="tables" VALUE="item_codes">item_codes<INPUT TYPE="radio"
    NAME="tables" VALUE="items">items<INPUT TYPE="radio" NAME="tables"
    VALUE="promo_codes">promo_codes<INPUT TYPE="radio" NAME="tables"
    VALUE="promotions">promotions<INPUT TYPE="radio" NAME="tables"
    VALUE="transactions">transactions<P><INPUT TYPE="submit" NAME="lflds"
    VALUE="List Fields"><INPUT TYPE="hidden" NAME=".cgifields"
    VALUE="tables"></FORM></BODY></HTML>

    For some reason the or condition trips for the system command,
    although the rc is zero. The HTML is correct, when pasted into a
    ..html and viewed it does display properly. Although via a browser
    none of the information from the file is on the page???? I removed
    the system (rm command and the file does not get created???
     
    Rob, Nov 15, 2003
    #1
    1. Advertising

  2. Rob

    Tore Aursand Guest

    On Sat, 15 Nov 2003 06:09:56 -0800, Rob wrote:
    > I have a small CGI script that attempts to create a file on the fly.


    First of all: Your subject is not the subject of your posting. The
    subject should be the _subject_ of the posting.

    > The script runs successfully from the command prompt.


    Which means that there are no errors in the script, right?

    > Although when I execute in a browser [...]


    No browsers - that I'm aware of - supports execution of Perl scripts. I
    might be wrong, though.

    What you actually mean, I guess, is that the web server executes, or tries
    to execute, the script. Right?

    Conclusion: There is obviously nothing wrong with your script as it runs
    fine from the command line. When the (web) server is trying to execute
    it, however, something fails. With this in mind, your question doesn't
    seem to be related to Perl at all, right?

    You should have posted your question in a newsgroup related to the (web)
    server which executes your Perl scripts.

    Am I totally wrong? If so, you should a described your problem better.

    > system("./list $dbin _ list.$$") || print "Bad Return Code from system
    > system("rm ./list.$$");


    Are you sure these system calls are necessary? For the latter, you could
    simple have used 'unlink';

    "Deletes a list of files. Returns the number of files success-
    fully deleted."

    Anyway: I'm pretty tried right now, and I didn't try to run your code,
    but I didn't see anywhere in the code that you try to create a file?


    --
    Tore Aursand <>
     
    Tore Aursand, Nov 15, 2003
    #2
    1. Advertising

  3. Rob wrote:

    [Subject: Help]

    The Perl help is called "perldoc". You use it by simply calling the command
    "perldoc" from the command line.
    Try "perldoc perldoc" for an explanation of options.

    > I have a small CGI script that attempts to create a file on the fly.
    > The script runs successfully from the command prompt.


    Then I guess your Perl program is correct.
    Please see "perldoc -q 500" for further trouble shooting information for CGI
    scripts.

    > Although when I execute in a browser


    I may be wrong but IFAIK there is no browser that could execute a Perl
    program.

    > the file does not get created [...]


    [program snipped]

    I may be wrong but there doesn't seem to be any command in that program that
    would create a file.

    jue
     
    Jürgen Exner, Nov 15, 2003
    #3
  4. Rob

    Ben Morrow Guest

    Tore Aursand <> wrote:
    > No browsers - that I'm aware of - supports execution of Perl scripts. I
    > might be wrong, though.


    If you install PerlScript which comes with AS perl then IE will... ;)

    Ben

    --
    "If a book is worth reading when you are six, *
    it is worth reading when you are sixty." - C.S.Lewis
     
    Ben Morrow, Nov 15, 2003
    #4
  5. Ben Morrow wrote:
    > Tore Aursand <> wrote:
    >> No browsers - that I'm aware of - supports execution of Perl
    >> scripts. I might be wrong, though.

    >
    > If you install PerlScript which comes with AS perl then IE will... ;)


    Perlscript != Perl script
    Or do you also believe that Javascript is the same as a Java script

    jue
     
    Jürgen Exner, Nov 15, 2003
    #5
  6. On 15 Nov 2003 06:09:56 -0800
    (Rob) wrote:

    Pick a more descriptive subject line next time :)

    <snip>
    > use CGI ':standard';


    use CGI qw:)standard -debug);

    Using '-debug' will allow you to test at the command line. Now you'll
    get:

    jim@maxine:~> perl news4.pl
    (offline mode: enter name=value pairs on standard input)
    database=X
    <CTRL-D> in *NIX or <CTRL-Z> in Windows

    Notice that I did not pass the parameters _at_ the command line, but
    was prompted for them. A lot easier to test :)

    perldoc CGI

    <snip>
    > system("./list $dbin _ list.$$") || print "Bad Return Code from
    > system call: $?\n";


    What is './list'? Can you execute just that at the command line?
    And why '||' instead of 'or'? 'or' is more readable. And why not
    'die' here? Later, you want to do something (it appears) with
    'list.$$'. Is this a check to make sure you're not overwriting a file
    that already exists?

    If so, then why not

    die "File exists\n" if(-e "list.$$");

    > open(FCELST, "list.$$") || print "Database $dbin is currently
    > unavailable: $!";


    Again, why 'print' instead of 'die'?

    <snip>

    > system("rm ./list.$$");


    More idiomatic Perl .....
    unlink "list.$$" or die "Remove of file failed\n";

    <snip>

    This, should, get you started.

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. http://www.gnu.org/licenses/gpl.txt
    for more information.

    a fortune quote ...
    Trying to be happy is like trying to build a machine for which
    the only specification is that it should run noiselessly.
     
    James Willmore, Nov 15, 2003
    #6
  7. Rob

    Ben Morrow Guest

    "Jürgen Exner" <> wrote:
    > Ben Morrow wrote:
    > > Tore Aursand <> wrote:
    > >> No browsers - that I'm aware of - supports execution of Perl
    > >> scripts. I might be wrong, though.

    > >
    > > If you install PerlScript which comes with AS perl then IE will... ;)

    >
    > Perlscript != Perl script
    > Or do you also believe that Javascript is the same as a Java script


    Of course not. PerlScript is simply Perl, though, with all the MS COM
    objects available as global variables as they are in Javascript.

    Ben

    --
    The cosmos, at best, is like a rubbish heap scattered at random.
    - Heraclitus
     
    Ben Morrow, Nov 15, 2003
    #7
  8. Rob

    Jay Tilton Guest

    (Rob) wrote:

    : I have a small CGI script that attempts to create a file on the fly.

    Not really. You have a program that attempts to invoke a second program
    which attempts to create a file. Big difference.

    : The script runs successfully from the command prompt. Although when I
    : execute in a browser the file does not get created and therefore the
    : contents are not displayed on the page. I have try several different
    : approaches all have fialed to correct this issue. I have checked the
    : promissions, I am login in under the httpd userid, I have checked the
    : rc on the system command(see below), and have hit the wall.
    :
    : HERE IS THE SCRIPT:
    : ****************************************************************************
    : #!/usr/bin/perl -w
    : use strict;
    : use CGI ':standard';
    :
    : my @fcetabs;
    : my @tablist;
    : my $dbin=param('database');
    :
    : system("./list $dbin _ list.$$") || print "Bad Return Code from system
    : call: $?\n";

    The error message will be emitted when system() returns 0 . External
    programs typically return 0 to indicate no error has occurred.

    Emphasize "typically." The ./list program is obliged to return non-zero
    in case of a show-stopping error, but it's not a certainty. It could be
    falling over dead and not telling anybody.

    The Perl program looks fine. Since the ./list program generates all the
    data used by the Perl program, troubleshooting efforts should be focused
    on what ./list is really doing. We know nothing about that program, so
    we cannot adequately help.

    : open(FCELST, "list.$$") || print "Database $dbin is currently
    : unavailable: $!";

    Instead of creating an intermediate data file, you might want to see if
    the data generated by ./list can be brought in through a piped open().
    Not only would it make the post-run file cleanup unnecessary, but it
    would prevent simultaneous CGI requests from wrecking each others' data.

    [snip remainder]
     
    Jay Tilton, Nov 15, 2003
    #8
  9. Rob

    Tore Aursand Guest

    On Sat, 15 Nov 2003 15:51:58 +0000, Ben Morrow wrote:
    >> No browsers - that I'm aware of - supports execution of Perl scripts.
    >> I might be wrong, though.


    > If you install PerlScript which comes with AS perl then IE will... ;)


    But, uh, ehm, who uses IE these days? *panicking*

    :)


    --
    Tore Aursand <>
     
    Tore Aursand, Nov 16, 2003
    #9
  10. Rob

    Lukas Mai Guest

    "Jürgen Exner" <> wrote:
    > I may be wrong but IFAIK there is no browser that could execute a Perl
    > program.


    w3m has a "local CGI" feature[1], so there is at least one browser that
    can execute Perl. ;-)

    HTH, Lukas
    [1] http://w3m.sourceforge.net/MANUAL#LocalCGI
     
    Lukas Mai, Nov 17, 2003
    #10
  11. On Sat, 15 Nov 2003 06:09:56 -0800, Rob wrote:

    > I have a small CGI script that attempts to create a file on the fly.
    > The script runs successfully from the command prompt. Although when I
    > execute in a browser the file does not get created and therefore the
    > contents are not displayed on the page. I have try several different
    > approaches all have fialed to correct this issue. I have checked the
    > promissions, I am login in under the httpd userid, I have checked the
    > rc on the system command(see below), and have hit the wall.
    >
    > HERE IS THE SCRIPT:
    > ****************************************************************************
    > #!/usr/bin/perl -w
    > use strict;
    > use CGI ':standard';
    >
    > my @fcetabs;
    > my @tablist;
    > my $dbin=param('database');
    >
    > system("./list $dbin _ list.$$")
    > || print "Bad Return Code from system call: $?\n


    Why do you reference "list" using a relative path? Are you sure the
    current directory when your server executes the script?

    If the execution of "list" fails, don't you want to croak or die instead
    of merely printing to STDOUT? Does "list" print anything to STDOUT which
    may mess up your HTTP headers?

    [snip rest of code /]

    > HERE IS THE OUTPUT FROM THE COMMAND LINE:
    > ****************************************************************************
    > /cgi-bin> listfce.cgi database=sample
    > Bad Return Code from system call: 0


    A return value of "0" indicates success. Perhaps you should use "and"
    instead of "||".

    Aloha,
    La'ie Techie
     
    LÄÊ»ie Techie, Nov 18, 2003
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    776
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    721
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    856
    Daniel
    Jul 16, 2004
  4. =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=

    HELP - HELP - HELP

    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    689
    Eliyahu Goldin
    Mar 9, 2006
  5. Buster

    Help, Help, Help

    Buster, Oct 4, 2003, in forum: Java
    Replies:
    3
    Views:
    479
    Saager
    Oct 30, 2003
Loading...

Share This Page