Page 1 of 1 1
Topic Options
#206647 - 2013-02-07 09:43 AM New function to get environment variables modified with SETL
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
As described in my post in the "Basic scripting" forum (Problem with environment vars ), there is a potential problem with SETL command. If a script modifies several times the same env variable with a reference to %env% (see code below), only the last change is available. Suppose the env var contains "P1" before kix32 starts :
 Code:
SETL ENV="P2;"+%env%  ; expected : P2;P1
...
...
SETL ENV="P3;"+%env%  ; expected : P3;P2;P1

SHELL "cmd /k set env"  ; display env=P3;P1

it would be nice to have :
- a new function to get the content of an environment variable modified with SETL, something like GETL( "ENV" )

or

- a new optional parameter in ExpandEnvironmentVars to expand strings with variables modified by SETL, something like ExpandEnvironmentVars( "%ENV%", 1 )

Kind regards,
Christophe


Edited by ChristopheM (2013-02-07 09:45 AM)
_________________________
Christophe

Top
#206648 - 2013-02-07 11:52 AM Re: New function to get environment variables modified with SETL [Re: ChristopheM]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
I just don't understand why you are trying to change the environment variables so many times. It should be a rare event. If you need to shell out to run a command that needs some particular environment variable set, then create a batch file that sets those variables and calls your command and then just shell out to the batch file from kix.

Am I missing something? I really didn't follow what you were trying to do, nor why it was necessary. Sorry.

Top
#206649 - 2013-02-07 04:52 PM Re: New function to get environment variables modified with SETL [Re: BradV]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
from the manual:
 Code:
SETL

Action

Sets environment variables in the local environment that you see when you start a program from within a KiXtart script.

 

Syntax

SETL "variable=string"

 

Remarks

This command does not affect the current environment.


and that is understandable. the env vars are not kixtart vars. you are using them inside kixtart script like you would kixtart vars.

I do think kixtart should support SET commands fully instead of just basically saying not implemented. But saying that, ENV vars are way slower to work with and the actual need for them just is not there.
_________________________
!

download KiXnet

Top
#206650 - 2013-02-07 05:15 PM Re: New function to get environment variables modified with SETL [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Christophe's requirement can also be managed entirely in Kix, which may be easier.
 Code:
$aENV = Split('%PATH%', ';')    ; get PATH as array when script loads
;
; now need to alter path
$NPath = 'C:\NewPath'
If AScan($aENV, $NPath) < 0     ; not found - add
  ; either create a new array starting with the NPath value, or
  ; extend the current array and add NPath value to the end
EndIf
$MyPath = Join($aPath, ';')
SETL 'PATH=' + $MyPath
By managing the path as an array, it's easy to determine if an element is present, insert or append an element, or remove an element prior and set the path to invoking any command.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#206652 - 2013-02-08 10:31 AM Re: New function to get environment variables modified with SETL [Re: BradV]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
in my company, we have about 4500 workstations and 400 applications (not all installed on all workstations) to manage. Very often, we can have up to 20 applications on a workstation with multiple middleware (oracle 9, oracle 11, java 1.5, Java 1.6, Java 1.7, etc...). The cohabitation of these softwares is not guaranteed by the editors so we try to do configuration dynamically at execution (not at installation).

1) When we launch an application, we have a .cmd script that launch a .kix script.
if we had to launch an other .cmd script to launch the .exe, it becomes complex.

2) We have to change many times because usually, applications need one or more middlewares. Each middleware is configured with a specific function. With all these middlewares, we can't change env var at the installation because this is the last installed that wins !!!

3) to answer to lonkero, i agree that env var can't be used like kix vars. But if an application needs Oracle 9 client (for example), the path var must contain reference to oracle 9 client directory (not Oracle 11 client). If a user needs simultaneously an application Oracle 9 and an application Oracle 11, I have to modify the local context of every application.

Unfortunatly, I don't decide how applications are coded and especially middlewares.
For example, Oracle modules are very "dirty". Cohabitation is not supported but in the real world, we must have cohabitation.

4) to answer to Glenn, the problem is not to control that a directory is already in the path. I already do that with array (like your code). The problem is to add several directories but not at the same time in the script. Several functions have to add ONE directory in the path. Now, there is no solution with integrated kix functions.


I can rewrite my own functions to replace SETL, SHELL or RUN and add a GETL function. This is not very complex but then, I shall have to modify approximately one thousand scripts to use these new functions. It is a very heavy operation with many risks. I shall also have to explain new functions to several scripters and control that they use theses functions correctly.

If I could have a integrated function like ExpandEnvironmentVars with an optional parameter, I would have to modify only some functions that are currently grouped in a library. The operation would be less heavy and the risks much more limited.


As Lonkero said, we would have no these problems if KiXtart implemented correctly the management of the current environment with SETL.

Thanks to all
_________________________
Christophe

Top
#206653 - 2013-02-08 12:02 PM Re: New function to get environment variables modified with SETL [Re: ChristopheM]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
Hi Christophe,

Well, first it sounds like your company needs to simplify applications a little. \:\)

So, if I understand it, you have a Windows command script which calls a kixtart script which then shells out and starts the application? If so, what are you doing in the kixtart script? Can it all just be accomplished in the command script?

Regards,

Brad

Top
#206655 - 2013-02-08 03:51 PM Re: New function to get environment variables modified with SETL [Re: BradV]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
When you initially run the bat file, is the path already set with with Oracle and Java paths. In other words, do you have to fix the path rather than build the path when you need some other flavor of Java or Oracle?
Top
#206663 - 2013-02-09 02:36 PM Re: New function to get environment variables modified with SETL [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Christophe, I can't see you guys needing to modify thousand scripts if this functionality you are seeking is not there now. so, either you have 1000 scripts that are misbehaving and do need to be corrected or they have not been even written yet.

either way, I've been inconvenienced by this myself long time ago and indeed kixtart has it's own environment but in the same sense, it would be only logical if it complied with the rules it relies on.
_________________________
!

download KiXnet

Top
#206685 - 2013-02-12 06:52 PM Re: New function to get environment variables modified with SETL [Re: BradV]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
sorry for delay.

1) BradV, changing the way to start application is not the matter now, maybe when we'll migrate to Windows 8 or Windows 8 (or later) but not now for XP.

Kix scripts are used to read-write ini configuration file, read or write values in registry, all things that aren't easy to do with .cmd scripts.

2) Allen, we have to build the path, not to fix it. As I said in my previous post, we configure environment (not only env vars) for application before starting application. this allows us to use test, production, formation versions of a same application on the same workstation, even if they are not really compatible (for example a parameter in the registry that gives the name of the database to connect to).

3) Lonkero, if i write my own functions, i have potentially one thousand of scripts to modify. May be i could let unchanged scripts that do not really need to be changed, but by experience, i know that all the scripts are going to become heterogeneous (i am not the only developperand all are not as perfectionist than I).
I agree with you, KiXtart should be compliant with env var management.

Regards,
Christophe
_________________________
Christophe

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.06 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org