Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: calling external programs via cgi perl script

by echoangel911 (Sexton)
on Mar 23, 2007 at 03:20 UTC ( [id://606157]=note: print w/replies, xml ) Need Help??


in reply to Re: calling external programs via cgi perl script
in thread calling external programs via cgi perl script

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)
  • Comment on Re^2: calling external programs via cgi perl script

Replies are listed 'Best First'.
Re^3: calling external programs via cgi perl script
by Fletch (Bishop) on Mar 23, 2007 at 04:37 UTC

    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.

        It doesn't work because you're trying to use csh commands in a Bourne shell. Explicitly run things with csh, or rewrite the environment variable setting script using sh syntax (as cdarke mentioned already above).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://606157]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found