Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running two commands in a single child process through system()

Status
Not open for further replies.

pankajpanjwani

Technical User
Mar 25, 2002
24
EU
Hi Experts,
I am trying to,
1. source a resource compiler file. (which sets some environment variable and appends the path)
2. Fire a job, for which uses the environment set in first step.
e.g for testing, it can be
step 1 : setenv TEST test
step 2 : echo $TEST

For, this I cannot use two separate "system" commands(as they will each invoke their own child process'. So I need to have one single child process, which sources that file and then invokes the application in same child process.

If you have any hint of solution, or you can suggest any then please help me.

thanks in anticipation
Pankaj
 
How do you feel about setting the environmental variables yourself?

I have these three lines in a file called "my.rc"

setenv TEST1 test1
setenv TEST2 "test2"
setenv TEST3 "test 3"

and then i can run the following script:

my $rcfile = "my.rc";
open RC, &quot;< $rcfile&quot; or die &quot;cannot open rc file: $!\n&quot;;
while (<RC>) {
if (/setenv\s+(\w+)\s+&quot;?(.*?)&quot;?$/) {
$ENV{$1} = $2;
}
}
system ('echo $TEST1');
system ('echo $TEST2');
system ('echo $TEST3');

which does this:

[538]Avalon[tek]$ perl env_test.pl
test1
test2
test 3

You would have to modify it somewhat if you have strange or long ( >1 line) env variable definitions.

jaa
 
My resource compiler file is not that simple, it also contains some constructs which cannot be set like this, you know how these cshrc's look like. e.g.
-----**------------**------------
if ( $?OPENWINHOME ) then
if ( $?LD_LIBRARY_PATH ) then
setenv LD_LIBRARY_PATH $OPENWINHOME/lib:$LD_LIBRARY_PATH
else
setenv LD_LIBRARY_PATH $OPENWINHOME/lib
endif
endif
-----**------------**------------

so, i feel your suggestion wont work in this case, but if it was simple then definitely this was the simplest solution.
Thanks for your efforts.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top