User Tools

Site Tools


accesssystempropertiesinscript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
accesssystempropertiesinscript [2023/01/14 16:33] – created wikiadminaccesssystempropertiesinscript [2026/01/25 14:48] (current) wikiadmin
Line 1: Line 1:
 =====Access and Use System Properties (-D defined properties) in a Script===== =====Access and Use System Properties (-D defined properties) in a Script=====
 +
 +<note>This article also applies to accessing and using parameters set in ErgoTechConfiguration.properties</note>
  
 This article shows you how to get the values of system properties which are defined on the command line using -Dpropertyname=value. There are other ways to set system parameters for MIX or TransSECS applications, and the code examples shown below will also work for these methods. In MIX you can add a parameter to the the mix.properties file, and for TransSECS deployments (and also for MIX applications running TransSECS code) you can add a parameter to ErgoTechConfiguration.properties. This article shows you how to get the values of system properties which are defined on the command line using -Dpropertyname=value. There are other ways to set system parameters for MIX or TransSECS applications, and the code examples shown below will also work for these methods. In MIX you can add a parameter to the the mix.properties file, and for TransSECS deployments (and also for MIX applications running TransSECS code) you can add a parameter to ErgoTechConfiguration.properties.
Line 9: Line 11:
 System properties are read as Strings. So if you have a variable in your application which is a numeric value you can do a numeric conversion on the String. Be sure to use a numeric value such as "0" as the property default in case the value is not defined on the commandline. System properties are read as Strings. So if you have a variable in your application which is a numeric value you can do a numeric conversion on the String. Be sure to use a numeric value such as "0" as the property default in case the value is not defined on the commandline.
  
-==== Access the Property Value ====+==== Access the Command Line Property Value ====
  
 The general idea to access these properties is to use System.getProperty("propertyname","optional default") The general idea to access these properties is to use System.getProperty("propertyname","optional default")
Line 18: Line 20:
 ipAddress=System.getProperty("ipaddress","192.168.0.2"); //use a default value if the parameter "ipaddress" is not defined ipAddress=System.getProperty("ipaddress","192.168.0.2"); //use a default value if the parameter "ipaddress" is not defined
  
-//now the ipAddress can be used to set the ip address of a device server+//now the ipAddress value can be used to set the ip address of a device server
  
-myDeviceServer->setHostName(ipaddress);+DeviceServer->setAddress(ipAddress); //note: setAddress method may be setHostname in some device servers
  
 </code> </code>
Line 33: Line 35:
 if (ipAddress!=null) { if (ipAddress!=null) {
  
-   myDeviceServer->setHostName(ipaddress);+   DeviceServer->setAddress(ipAddress);
 } }
  
 </code> </code>
 +
 +==== Store Parameters in a Variable ====
 +
 +If you are going to use this parameter in your project's scripting often, you can store this value in a "Variable" in the /Devices/Utility_Servers node of your project. 
 +
 +Add a "Variable" (BroadcastServer) to your Utility_Servers, for example add a Variable called "IPAddress". Taking the code from the example above, after reading the value for ipAddrss, you can store it in this new Variable for later access. Alternatively you can just use System.getProperty() again to get this value whenever you need to.
 +
 +<code javascript>
 +var System = Java.type("java.lang.System");
 +
 +ipAddress=System.getProperty("ipaddress"); //ipAddress will be null if "ipaddress" is not defined
 +
 +if (ipAddress!=null) {
 + //store the ipAddress in the Variable "IPAddress" for access later
 +   /Devices/UtilityServers_Servers/IPAddress->setStringValue(ipAddress);
 +}
 +
 +</code>
 +
 +Any time after this in your scripts you can access the current value of "IPAddress" using the syntax ipAddress=/Devices/UtilityServers_Servers/IPAddress->getStringValue();
accesssystempropertiesinscript.1673732033.txt.gz · Last modified: by wikiadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki