Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    change var $PATH within a perl CGI

    HI,
    I created a webservice that uses a CGI with perl.
    Within the perl script, I call another perl code whose
    path has to be in the $PATH variable to work.
    My command is like this:

    system("program > outputfile");

    changing the path in the .bashrc or .profile of course
    does not work because the user is www-data and
    not the user whose folders contain the program I
    am trying to call.

    This method does not work either:
    system("perl -I/home/name/public_html/program/bin program > outputfile");
    /home/name/public_html/program/bin being the path I am trying to
    append to $PATH variable.
    Do you have an idea of what I should do? Thanks in advance.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Why do you need the path to be in the environment variable?

    $ENV{'PATH'} .= ';/home/name/public_html/program/bin';

    As long as the path and the script is setup with the proper permissions to allow the web server account to access and run the script, you could simply provide the full path when executing the script.

    Instead of the system call, you could call it via 'do'. See: perldoc -f do

  • #3
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the help but unfortunately this did not work.
    Logged as local user, launching this program (the one that
    requires to path to be changed, not my cgi script) at the command
    line works, as the path is set up on my .profile file.
    From internet it does not work, and I know that it comes
    from the path because I got the exact same problem as
    when path is not set up using command line. Anyone any
    other idea how to set the path? Thanks in advance.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by mrdvd030 View Post
    Thanks for the help but unfortunately this did not work.
    Logged as local user, launching this program (the one that
    requires to path to be changed, not my cgi script) at the command
    line works, as the path is set up on my .profile file.
    From internet it does not work, and I know that it comes
    from the path because I got the exact same problem as
    when path is not set up using command line. Anyone any
    other idea how to set the path? Thanks in advance.
    try:
    Code:
    system("/home/name/public_html/program/bin/program > outputfile");
    but if 'program' need to be run in the same dir where it is you need to cd first to that dir.

    i bet you don't use pragma strict and warnings, is bad habit,

    best regards

  • #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    If adding the path to the environment or specifying the full path when executing the program doesn't work, then the problem is the path. It's either permissions or some other environment setting that you're doing in your .profile which is not being set in the web server environment.

    It's hard to help you any further without more info from you, specifically any/all warnings and errors that your script produces. If you haven't already done so, add these lines to the beginning of your script and tell us what happens.
    Code:
    use strict;
    use warnings FATAL => 'all';
    use CGI::Carp qw( fatalsToBrowser );

  • #6
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the fast answers.
    My web server has no errors. It runs well, program
    I call is recognized and even creates a folder but
    without specifying the path it does not generate the
    output it should generate. I had the same problem
    using the command line. Since I did not specify the
    path, the program generated a folder but no output
    in it. So I guess its the same problem from the
    internet. But if its a permission problem, I do not
    see how to overcome it.
    Yes, I use strict and warnings and display erros in my
    browser. Thanks if you have another idea.

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by mrdvd030 View Post
    Thanks for the fast answers.
    My web server has no errors. It runs well, program
    I call is recognized and even creates a folder but
    without specifying the path it does not generate the
    output it should generate. I had the same problem
    using the command line. Since I did not specify the
    path, the program generated a folder but no output
    in it. So I guess its the same problem from the
    internet. But if its a permission problem, I do not
    see how to overcome it.
    Yes, I use strict and warnings and display erros in my
    browser. Thanks if you have another idea.
    did you tried what i said? both suggestion?

    best regards

  • #8
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    If you're not getting any errors/warnings when it fails, then that tells me that your error handling is insufficient.

    Please post your code so we can have a better idea of what you're doing and how you're going about it.


  •  

    Posting Permissions

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