in reply to calling external programs via cgi perl script

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.

  • Comment on Re: calling external programs via cgi perl script

Replies are listed 'Best First'.
Re^2: calling external programs via cgi perl script
by echoangel911 (Sexton) on Mar 23, 2007 at 03:20 UTC
    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

        One other thing to add to the above. You appear to be using csh (you mentioned setenv previously). system and backticks use the Bourne shell, which does not have the source command (uses 'dot' instead) and the syntax for setting variables is different. You will have to explicitly call csh (or tcsh) to get your file to run.
        for some reason, source foo; doesn't work for me. this is my foo file:
        #!/bin/tcsh set circuit_os = Linux.7.3 setenv CIRCUIT_LIC /tools/circuit/difflib/asdf.lic setenv SERVER_LIC /tools/circuit/difflib/server.lic
        and when I execute this:
        my @lines =`. foo; env`; foreach my $line (@lines) { print "[DEBUG] $line <br>\n"; }
        I don't understand why I'm also getting this:
        sh: line 6: setenv: command not found sh: line 7: setenv: command not found
        I don't see any of those variables in output.