Solved

Sourcing a .cshrc-like file from within a perl script

Posted on 2000-04-14
6
177 Views
Last Modified: 2010-03-05
On an Irix platform, I have the following files:

*a file that contains environmental variables
*an executable file main.exe

If I try to do something like:
1 #!/usr/bin/perl
2 system ("source sourcefile");
3 system ("main.exe");

then main.exe ends up dying because the environmental variables don't stick after line 2.

I've also tried:
1 #!/usr/bin/perl
2 eval ("source sourcefile");
3 eval ("main.exe");

with no success.

My current workaround is:
1 #!/usr/bin/perl
2 system ("doeverything");

where "doeverything" is a separate C-shell script that sources sourcefile correctly and properly runs main.exe.

Is there a better way to do this, without using the C-shell?  Or am I stuck using this method?

Constraint: sourcefile and main.exe cannot be massaged into perl.

Thanks in advance.
0
Comment
Question by:peyo
6 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2716544
try this...

system ("source sourcefile; main.exe;");

that way both the files are executed in the same shell and therefore have the same environment variables.

0
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2717047
You could try forking 2 processes in PERL using fork
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 2717810
system 'csh','-c','source sourcefile; main.exe';
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:jyu_88
ID: 2718305
supposedly, you should define environmental variable for yourself in perl, preferrablly in a BEGIN{} block, then go on with your deeds.Assume all env is set by 'setenv' in the current .cshrc.#! /usr/bin/perl -wBEGIN {open CSHENV, "< /home/user88/.cshrc" or die "Failed to read /home/uesr88/.cshrc: $!";while(<CSHENV>) {
if(/\s*^\s*setenv\s (. ?)\s (. ?)\s*$/) {
$ENV{$1} = $2
}}}
0
 
LVL 1

Author Comment

by:peyo
ID: 2723813
maneshr--Tried that before. That doesn't work.
chris18--Unacceptable. The source variables have to be visible to the main program.
jyu--There is no need for the sourced variables to be visible to the perl program. They only need to be visible to the main.exe program
ozo--I think you might be on to something. I'm testing this further...

0
 
LVL 1

Author Comment

by:peyo
ID: 2724043
maneshr--Tried that before. That doesn't work.
chris18--Unacceptable. The source variables have to be visible to the main program.
jyu--There is no need for the sourced variables to be visible to the perl program. They only need to be visible to the main.exe program
ozo--I think you might be on to something. I'm testing this further...

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now