Focal Point
iSM IFL for reading Environment variables

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/1381057331/m/6657084616

February 09, 2012, 07:23 PM
AK
iSM IFL for reading Environment variables
Hello,

Is there an iWay function in Service Manager 6.1.2 which can retrieve the value of a Windows System Environment variable?

Thanks.


iSM 616
iDM 7705
iDQC 802
WF 77
Windows 2008 Server
February 10, 2012, 09:55 AM
Igor Y
I don't think there is a function, but if you change your iSM startup script to include the variable in the java properties, like -Dwindir=%windir%, you might be able to use _sreg(windir).


iWay Service Manager (6.0.1 - patch.62627)
DMC Version 7 Release 7
February 10, 2012, 01:59 PM
iWay Newbie
Hi AK,

there is no direct function, but there's a _property() iFL... If you do

C:\> set > myvars.txt

You should be able to get the values from the file.

The easiest is probably to call the service that invokes OS commands:

Run OS Shell Command Service (com.ibi.agents.XDRunCmdAgent)

The command would be "cmd /C set" to get a list of all variables under /status/cmdoutput or "cmd /C set prompt" to get the value of the PROMPT variable....

<?xml version="1.0" encoding="UTF-8" ?>
<status>
	<command>cmd /C set prompt</command>
	<exitcode>0</exitcode>
	<cmdoutput>PROMPT=$P$G</cmdoutput>
</status>


Hope this helps!

Newbie.


--
WebFOCUS 8.2.03 on Linux
February 14, 2012, 12:21 PM
Dan Satchell
I know nothing about Service Manager and iWay functions, but there is a WebFOCUS function, FGETENV, that is used to retrieve values from system environment variables. You could see if it works in iWay.

Syntax: How to Retrieve the Value of an Environment Variable

FGETENV(varlength, 'varname', outfieldlen, outfldformat);

where:

varlength=Integer  - Is the length of the environment variable name.

varname=Alphanumeric  - Is the name of the environment variable.

outfieldlen=Integer  - Is the length of the field in which the environment variable's value is stored.

outfldformat=Alphanumeric  - Is the format of the field in which the environment variable's value is stored.



WebFOCUS 7.7.05
February 15, 2012, 11:06 AM
AK
WebFOCUS / iDM function FGETENV does not work in iSM.

One comment about FGETENV function in iDM is whenever the Windows environment variable value changes, iDM server has to be restarted to load the new value. If the server is not restarted the function always retrieves the old value. Looks like this function does not call the env var directly but rather calls the variables that are loaded in memory when the server is started.


iSM 616
iDM 7705
iDQC 802
WF 77
Windows 2008 Server
February 21, 2012, 02:37 PM
Clif
I'm not sure your comment about FGETENV is quite correct; when you issue a set from a DOS prompt it's not going to affect the server running as a service or in its own DOS window.

However if you set an environment variable from withinthe running server, that would be fine. For example:

 -SET &RC= FPUTENV(9, 'IWAF_HOME', 7, 'C:\IWAF', 'I8');
-SET &IWH = FGETENV(9, 'IWAF_HOME', 20, 'A20');
-TYPE &IWH 



N/A
February 22, 2012, 08:59 AM
dhagen
Or you can just write one:

Code: FunctionNodeGetEnv.java
package com.ibi.funcs;
import com.ibi.edaqm.*;

public class FunctionNodeGetEnv extends FunctionNode {

	public FunctionNodeGetEnv() {
		super("GetEnv");
	}
	
	public FunctionNodeGetEnv(String name) {
		super("GetEnv");
	}
	
	String getTypeName() {
		return "GetEnv";
	}
	
	public int getMinParms() { 
		return 1; 
	}
	
	public int getMaxParms() { 
		return 1; 
	}

	public XDNode getDesc()	{
		try {
			String info =
				"<func name='_getenv' class='string'>" +
				"<desc>Get Environment Variable value.</desc>" +
				"<parm name='string' type='string' req='yes'>Enviornment variable to return</parm>" +
				"</func>";
			XDDocument d = new XDDocument(null,info);
			return d.getRoot();
		} catch (Exception e) {
			return null;
		}
	}
	
	private FunctionNode[] parms;
	
	public void optimize(XDManager manager, com.ibi.common.IXLogger logger) throws XDException	{
		super.optimize(manager,logger);
		parms = getParms();
	}
	
	public String getXValue(XDDocument doc, com.ibi.common.ISpecRegManager srm, com.ibi.common.IXLogger logger) throws XDException	{
		/* Initialize return string */
		String eValue = null;

		/* Ensure there is 1 arguments in the function call */
		if (parms.length != 1) {
			throw new XDFunctionException("_GetEnv",1,"Function requires min 1 argument.");
		}
		
		/* Retrieve the in bound arguments */
		String arg1 = parms[0].getXValue(doc, srm, logger);

		/* Get the environment variable */
		try{
			eValue = System.getenv(arg1);
		}catch (Exception e){
			throw new XDFunctionException("_GetEnv",1,"_getenv failed.");
		}

		/* return environment variable if available */
		return (eValue == null ? " " : eValue);
	}
}
  


Code: GetEnvRegister.java
package com.ibi.funcs;

public class GetEnvRegister implements com.ibi.common.IComponentRegister {
	public GetEnvRegister() {
	}

	public void register (com.ibi.common.IComponentManager cm) {
		cm.addFunction("_getenv","com.ibi.funcs.FunctionNodeGetEnv");
	}
	public void unregister (com.ibi.common.IComponentManager cm) {
	}
}  


Manifest:
Name: IXTEComponent
Register: com.ibi.funcs.GetEnvRegister
  


Usage:
 _getenv('temp') 


Returns:
 C:\DOCUME~1\dhagen\LOCALS~1\Temp 



"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
February 23, 2012, 04:59 AM
AdeH
I haven't tried this, but many thanks to dhagen for a top quality answer!


iWay 5.5 SMSP1 and 6.0.1 on Intel/Linux