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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very simple TCL script problem

Status
Not open for further replies.

atamel

Programmer
Feb 24, 2005
3
US
Hi,

I have a file called setup.weka.sun which basically sets up Weka environment. The content of setup.weka.sun is as follows.
**********************************************************
set MyDeptRoot = /r/aiml/ml-software/
set MyAgasRoot = ~/Experiments/ml-software/
set MyRoot = $MyDeptRoot

set Version = weka-3-2-3/weka-3-2-3

use jdk1.4.1
setenv WEKAHOME $MyRoot/$Version/
setenv WEKADATA $MyRoot/datasets/weka/UCI/
setenv CLASSPATH .:$MyRoot/$Version/weka.jar

unset MyDeptRoot
unset MyAgasRoot
unset MyRoot
**********************************************************

Normally, you would just type "source setup.weka.sun" to setup Weka environment on UNIX. I want to do this from a Perl script. So in my Perl script, I do the following.

$result = `source setup.weka.sun`;

For some reason, $result is always empty and Weka is never set. I know this is a simple problem but I couldn't find a way around it. Can someone help?
 
I could be wrong, but you are using a system call which means that the environment exists for that system call only as it spawns it own shell to run within. It does not add the environment to your current environment where you are running your PERL code. You will need to call source in a shell before executing your PERL code if you need it during the execution of the PERL code.


Michael Libeson
 
Backticks return the stdout of the code run inside the backticks. Since the code you posted (C shell?) doesn't have any output, I'd expect $result to be empty.

source is a command used in C-shell (and maybe some other shells) to execute code in the same shell as the parent rather than in another shell. Since the code executed in backticks is executed in another shell, for practical purposes it's meaningless here.

Take a look at the following thread: thread219-999775, in particular apostate's post near the end of the thread. This deals with a situation which I think is much like yours, and the module apostate mentions should allow you to do what you want.

HTH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top