Solved

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

Posted on 2000-04-14
6
181 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl, group, sort, count question 6 149
Parse csv file and generate graphs in HTML in bash 8 272
Get a Perl script to return content from a module 7 83
combine multiple lines 2 73
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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 …
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…

685 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