?
Solved

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

Posted on 2000-04-14
6
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 total points
ID: 2717810
system 'csh','-c','source sourcefile; main.exe';
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

752 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