
Anonymous
Not applicable
2009-10-06
02:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[resolved] How to get an environment variable from the system into a context var?
I am looking to implement the following scenario:
Setup a system environment variable on the server that Talend is running on. The value of this variable will be a path to a folder containing XML files that I use for various purposes. At runtime in my job, I would like to use some Talend component to retreive the value of the environment variable and store it in a context variable. I can then use that context variable as the leading source string for my tXMLInput.
I see a tSetEnv, but I do not see a tGetEnv comnponent.
Any easy way to do this?
thanks,
Dave
Setup a system environment variable on the server that Talend is running on. The value of this variable will be a path to a folder containing XML files that I use for various purposes. At runtime in my job, I would like to use some Talend component to retreive the value of the environment variable and store it in a context variable. I can then use that context variable as the leading source string for my tXMLInput.
I see a tSetEnv, but I do not see a tGetEnv comnponent.
Any easy way to do this?
thanks,
Dave
1,724 Views
- « Previous Replies
-
- 1
- 2
- Next Replies »
1 Solution
Accepted Solutions

Anonymous
Not applicable
2009-10-07
10:38 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi;
To retrieve your environment variable use the following into a tJava (begin of your Job) like this : context.MyPath = System.getProperty("SYSTEM_ENV");
Best regards;
To retrieve your environment variable use the following into a tJava (begin of your Job) like this : context.MyPath = System.getProperty("SYSTEM_ENV");
Best regards;
1,627 Views
10 Replies

Anonymous
Not applicable
2009-10-07
10:38 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi;
To retrieve your environment variable use the following into a tJava (begin of your Job) like this : context.MyPath = System.getProperty("SYSTEM_ENV");
Best regards;
To retrieve your environment variable use the following into a tJava (begin of your Job) like this : context.MyPath = System.getProperty("SYSTEM_ENV");
Best regards;
1,628 Views

Anonymous
Not applicable
2009-10-07
02:07 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi;
To retrieve your environment variable use the following into a tJava (begin of your Job) like this : context.MyPath = System.getProperty("SYSTEM_ENV");
Best regards;
Thanks! Sounds like tSetEnv needs a brother (tGetEnv)
Dave
1,627 Views

Anonymous
Not applicable
2009-11-18
01:59 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi;
To retrieve your environment variable use the following into a tJava (begin of your Job) like this : context.MyPath = System.getProperty("SYSTEM_ENV");
Best regards;
Thanks! Sounds like tSetEnv needs a brother (tGetEnv)
Dave
In the following code, the commented out line works, but sun java documentation says that getenv is deprecated. The uncommented line (getProperty) only works when I query for java.xxx properties (ex: java.io.tmpdir), but returns null when I use system environment vars. System.getProperty() is a java function.
Also, I assume that this same command can be used against linux?
context.CCRHome = System.getProperty("CCR_HOME");
//context.CCRHome = System.getenv("CCR_HOME");
???
Dave
1,627 Views

Anonymous
Not applicable
2009-11-18
10:32 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Dave
Please use the following routine, it both works on windows and Unix/Linux.
Best regards
shong
Please use the following routine, it both works on windows and Unix/Linux.
// template routine Java
package routines;
import java.io.*;
import java.util.*;
public class getEnv {
static String value = null;
public static String getEnvValue(String key) {
try {
Properties p = getEnv.getEnvVars();
value = p.getProperty(key);
} catch (Throwable e) {
e.printStackTrace();
}
return value;
}
public static Properties getEnvVars() throws Throwable {
Process p = null;
Properties envVars = new Properties();
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("windows 9") > -1) {
p = r.exec("command.com /c set");
} else if ((OS.indexOf("nt") > -1) || (OS.indexOf("windows 2000") > -1)
|| (OS.indexOf("windows xp") > -1)) {
p = r.exec("cmd.exe /c set");
} else {
// it is Unix os.
p = r.exec("env");
}
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
int idx = line.indexOf('=');
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
envVars.setProperty(key, value);
}
return envVars;
}
}
Best regards
shong
1,627 Views

Anonymous
Not applicable
2009-11-19
10:51 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Dave
Please use the following routine, it both works on windows and Unix/Linux.// template routine Java
package routines;
import java.io.*;
import java.util.*;
public class getEnv {
static String value = null;
public static String getEnvValue(String key) {
try {
Properties p = getEnv.getEnvVars();
value = p.getProperty(key);
} catch (Throwable e) {
e.printStackTrace();
}
return value;
}
public static Properties getEnvVars() throws Throwable {
Process p = null;
Properties envVars = new Properties();
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("windows 9") > -1) {
p = r.exec("command.com /c set");
} else if ((OS.indexOf("nt") > -1) || (OS.indexOf("windows 2000") > -1)
|| (OS.indexOf("windows xp") > -1)) {
p = r.exec("cmd.exe /c set");
} else {
// it is Unix os.
p = r.exec("env");
}
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
int idx = line.indexOf('=');
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
envVars.setProperty(key, value);
}
return envVars;
}
}
Best regards
shong
Thanks shong.
1,627 Views

Anonymous
Not applicable
2009-11-20
11:05 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Dave
Please use the following routine, it both works on windows and Unix/Linux.// template routine Java
package routines;
import java.io.*;
import java.util.*;
public class getEnv {
static String value = null;
public static String getEnvValue(String key) {
try {
Properties p = getEnv.getEnvVars();
value = p.getProperty(key);
} catch (Throwable e) {
e.printStackTrace();
}
return value;
}
public static Properties getEnvVars() throws Throwable {
Process p = null;
Properties envVars = new Properties();
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("windows 9") > -1) {
p = r.exec("command.com /c set");
} else if ((OS.indexOf("nt") > -1) || (OS.indexOf("windows 2000") > -1)
|| (OS.indexOf("windows xp") > -1)) {
p = r.exec("cmd.exe /c set");
} else {
// it is Unix os.
p = r.exec("env");
}
BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
int idx = line.indexOf('=');
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
envVars.setProperty(key, value);
}
return envVars;
}
}
Best regards
shong
Thanks - I ended up using getEnv("CCR_HOME") in java, and that worked fine.
1,627 Views

Anonymous
Not applicable
2009-11-22
12:22 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can simply use System.getenv("myvar") in java, without an external code.
bye
bye
1,627 Views

Anonymous
Not applicable
2009-11-30
11:08 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
right - that worked great.
Thanks,
Dave
Thanks,
Dave
1,627 Views

Anonymous
Not applicable
2009-12-17
02:17 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Shong,
Nice solution. Thanks!
Nice solution. Thanks!
1,627 Views

- « Previous Replies
-
- 1
- 2
- Next Replies »