Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

calling external programs via cgi perl script

by echoangel911 (Sexton)
on Mar 22, 2007 at 22:56 UTC ( #606119=perlquestion: print w/ replies, xml ) Need Help??
echoangel911 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Everyone, I been very puzzled to this problem. I wrote a cgi and I want to execute this tool command (batch mode). However it seems I get nothing . I have tried system and `. The cgi is on a unix webserver. Any ideas on what I am doing wrong? How can this be resolved?

Comment on calling external programs via cgi perl script
Re: calling external programs via cgi perl script
by Joost (Canon) on Mar 22, 2007 at 23:02 UTC
      the code looks like this
      print `source command`; print system("source command");
      i'm getting a value or -1 for the system my cgi page works fine without the command line. If I source the command file on my xterm window, it works fine
        inside the command file, there is a line that sources some environment paths and variables.
        Sourcing a shell script from system() will not do anything more useful than just running the script using system() - if it works at all (not sure, since source isn't a command but a shell built-in). Also, a return value of -1 from system() indicated a failure to execute the provided command.

        Anyway, that's still not enough information to help you fix the problem.

        Does the CGI script run as expected from the command line? What is the exact line of code you're using to run the script?And most importantly, what's in the error logs?

Re: calling external programs via cgi perl script
by Fletch (Chancellor) on Mar 22, 2007 at 23:03 UTC

    Well, considering you've given very few details and none of the code you're trying to use it could be anything. Your code could be wrong. The program you're trying to run might have some dependencies on its environment that's not set when run from under your webserver. It could require a TTY. There could be permissions problems (file ownership, the UID you're running as could be unable to write something, . . .).

    So no, probably not going to get much help. More specifics possibly will rectify that.

      I need to make some system calls to other programs from a perl program and those programs that are being called have some environment variable dependencies that are set by a shell script program. So I have to call this shell script to set up (set variables) environment variables so that the other program that I call can run fine. when calling the command script on the command line, I see these environment variables aren't being passed and die with errors. (ie doesn't understand setenv command)

        You can't do that, at least not directly. When you run source foo it's in a child shell and only that child shell's environment is modified. When that shell ends, all those modifications go away. See perlfaq8, "I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?"

        You'd need to source the file and run the rest of the commands in the same subshell. Prefix the commands that need the modified environment with the source command separated by a semicolon: source foo ; some_other command

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://606119]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-09-22 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (208 votes), past polls