Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2000-04-14
6
Medium Priority
?
187 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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

610 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