Solved

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

Posted on 2000-04-14
6
176 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

19 Experts available now in Live!

Get 1:1 Help Now