Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying write a script that can automatically set the display variable on an AIX server to run X applications over telnet, that can be ran from a users .cshrc file.
#!/usr/bin/perl -w # /usr/local/bin/gethost.pl # Find out where I'm calling from open(WHOPROC, "who -m|"); # open who for reading $whoami = <WHOPROC>; close (WHOPROC); # print "$whoami"; ($name,$port,$month,$day,$time,$host) = split(/\s+/, $whoami); chop $host; $grab = substr($host, 1,); #print "$grab\n"; # Now set the display variable $display = $grab . ':0.0'; # print "$display\n"; system "sh export DISPLAY='$display'";
Is there a way to make perl set the variable for the parent telnet session?

Replies are listed 'Best First'.
Re: setting enviornment variables for parent process
by chromatic (Archbishop) on Feb 09, 2000 at 23:38 UTC
    The system call actually forks a child process, runs exec on the process, waits for the process to exit, then returns.

    So what you're doing is spawning a new process and setting an environment variable in that process. Then the process exits, the environment variable is lost, and you're left scratching your head. (Just thought you might like to know why system wasn't appropriate here. :)

RE: setting enviornment variables for parent process
by setantae (Scribe) on Feb 09, 2000 at 07:58 UTC
Re: setting enviornment variables for parent process
by jamieamieamily (Initiate) on Feb 09, 2000 at 17:58 UTC
    If this is to be run from a .cshrc then will the perl script also be executing any X applications? If so then setting the DISPLAY environment variable within the script is fine:
    $ENV{DISPLAY}="$grab:0.0";
    Otherwise why use a perl script to export the value of $DISPLAY?
      Mainly I'm just trying to learn perl as I have no programming experience at all. Also I was just trying to figure out a way so that users wouldn't have to type setenv DISPLAY 'theirhost:0.0' everytime they telnetted into the server. I tried ssh which works great as far as that respect but for really intesive X applications like Arcview and Arcinfo the encryption causes some major lag and hangups when moving or resizing windows.
        I suspect the encryption can be disabled for ssh. Consider doing this on an as-needed basis.