Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2004
    Location
    Eternity
    Posts
    31

    Unanswered: Perl Gurus..Please help

    Iam facing a peculiar problem in one of the perl/shell scripts. Iam at my wits end on how to resolve this issue. Seeking the help of Perl Gurus..

    Here goes the problem



    Iam trying to call a shell script from a perl script.

    The shell script inturn invokes a Java program to download some data from a database.

    The script works fine if I run the perl script from the command line.

    But when I invoke the script thru the browser, the download doesnot happen but the script doesnot return any error either.



    I tried to call the java program directly from the perl script using system() but still the behaviour is the same.The call to the java program doesn’t seem to get executed but no error is returned and the rest of the script gets executed normallly.



    The CLASSPATH doesn’t seem to be an issue as the script runs fine when run from the command line.

    The dir permission problem is also ruled out.



    Any inputs on why this happenning?



    Thanks in advance…



    --Vijay
    Obviousness is the enemy of Correctness
    --Bertand Russel

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Hi!

    I can't give you a solution vithout more details. How your script starts?? I would recommend to use these lines:
    Code:
    #! /usr/bin/perl
    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    [...more uses...]
    my $cgi = CGI->new();
    print $cgi->header(-type => text/html);
    warningsToBrowser(1);
    [...rest of the script...]
    fatalsToBrowser displayes error messages on the browser and warningsToBrwoser does it with warnings...
    Maybe this helps you to find your problem...
    board.perl-community.de - The German Perl-Community

  3. #3
    Join Date
    Feb 2004
    Location
    Eternity
    Posts
    31
    Tried to put the code that you supplied in my script.
    My server gives an error when I put "use strict" or for that matter any uses in the script.
    Looks like I need to contact my server helpdesk first.
    Obviousness is the enemy of Correctness
    --Bertand Russel

  4. #4
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    use strict; forces sou to declare all variables with "my". It looks like this:
    Code:
    #! /usr/bin/perl
    
    use strict;
    use warnings;
    
    my $file = 'filename';
    my $var = 'another variable';
    This avoids a lot of errors caused by typos.

    If it is to heavy to declare all the variables in this script with my, you can miss it. But I would recommend to use in further scripts...
    You should use the other lines I supplied in this script for debugging.
    board.perl-community.de - The German Perl-Community

  5. #5
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Hi senza_nome,

    your code looks fine, but I've some comments on it:

    *) You're using the -w flag. This can end in some problems, because this flag checks included modules for warnings. Especially older modules cause warnings you don't want to get.
    I would recommend to use "use warnings;". It is limited to your own script. I think this is enough.

    *) You are using an Environment-variable. You cannot be sure, whether this variable is set or not. The browser "decides" which environment variables are sent. You should use $0 (see http://www.perldoc.com/perl5.8.4/pod/perlvar.html).

    *) You do not catch warnings (you do not display the messages in the browser). Often warnings are very useful for debugging.

    But overall it seems to be a very helpful piece of code. I'm going to check it more detailed within the very next days. Thanks!
    board.perl-community.de - The German Perl-Community

  6. #6
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Look at: http://hoohoo.ncsa.uiuc.edu/cgi/env.html

    Only
    * SERVER_NAME
    * SERVER_SOFTWARE
    * GATEWAY_INTERFACE
    are non-request-specific.

    So the use of $ENV{SCRIPT_NAME} can be a lack of security, because anybody can set this variable to any value he want.
    To patch this lack I would recommend to use $0 . This is an perl-internal variable...

    I would be grateful, if anybody, who is very familiar with CGI and environment variables, can give an advise, whether I'm right or not!
    board.perl-community.de - The German Perl-Community

  7. #7
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    If you can, test this script on many machines with many browsers and you will see that the environment variables are different. I - by myself - would ensure the functionality of my scripts by using perl-internal variables. These variables have always - except a bug in your perl-version - the right value...

    Code:
    #! /usr/bin/perl
    
    use strict;
    use warnings;
    
    print "Content-type: text/plain\n\n";
    
    foreach(keys(%ENV)){
      print $_,":\t",$ENV{$_},"\n";
    }
    board.perl-community.de - The German Perl-Community

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •