Talend (Ubuntu) - Read System Variables

Six Stars

Talend (Ubuntu) - Read System Variables

I wanted to create a flow which would pick a configuration file based on the system variable "WORK_ENV". While I could do "echo $WROK_ENV" and can get the desired output on the console, I can't seem to do that in the Java node of my talend job.

 

Have tried using System.getenv("WORK_ENV") as well as the newer System.getProperty("WORK_ENV"). Both of them yield null.

 

Web search suggests me that the same constructs are working for people but for some odd reason, it isn't working for me.

 

The Talend Version is Open Studio 7.0.1, on Ubuntu 16.04LTS


Accepted Solutions
Sixteen Stars

Re: Talend (Ubuntu) - Read System Variables

This seems very odd. Can you build a job with 1 tJava component only and add this code to it....

 

System.out.println(System.getenv("WORK_ENV"));

When you run it, can you see your variable value?

Nine Stars

Re: Talend (Ubuntu) - Read System Variables

Once the tSSH component successfully executes the commands and provided that you have selected the standard output as global variable you could access the value in your next components like this - 

((String)globalMap.get("tSSH_1_STDOUT"))

 

Six Stars

Re: Talend (Ubuntu) - Read System Variables

It was weird but the same code worked fine. I might have missed a little detail somewhere, which I am still unable to figure out. Thanks Abhishek and Rhall. I certainly learnt few more things in the process.


All Replies
Nine Stars

Re: Talend (Ubuntu) - Read System Variables

Did you try to get the output of "echo $WROK_ENV" to global variable instead of console?
Six Stars

Re: Talend (Ubuntu) - Read System Variables

Not sure if I followed your recommendedation, Abhishek. Is there a way that I can echo/ print in the talend? Just to ensure that there is no confusion, if I do "echo $WORK_ENV" on the ubuntu terminal, I can see the following output.

 

Screenshot from 2018-08-13 13-11-04.png

Nine Stars

Re: Talend (Ubuntu) - Read System Variables

We have a Talend Component named tSSH where you could invoke your commands, for your scenario - "echo $WORK_ENV".

Now you have to define the Standard Output for tSSH to "global variable" so that you could catch the output and make use of it in your next steps/components.

Six Stars

Re: Talend (Ubuntu) - Read System Variables

Good to know info. Thanks.

 

I tried utilizing the tSSH component and was able to print the value of the system variable. How do I utilize that in my flow is what still troubles me.

 

Starting job test_process_only_latest_file_opt2 at 13:36 13/08/2018.

[statistics] connecting to socket on port 3542
[statistics] connected
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.15.0-30-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

Last login: Mon Aug 13 13:35:24 2018 from 127.0.0.1

echo $WORK_ENV
exit
pas@ubuntu:~$ echo $WORK_ENV
dev
pas@ubuntu:~$ exit
logout
[statistics] disconnected

Sixteen Stars

Re: Talend (Ubuntu) - Read System Variables

This seems very odd. Can you build a job with 1 tJava component only and add this code to it....

 

System.out.println(System.getenv("WORK_ENV"));

When you run it, can you see your variable value?

Nine Stars

Re: Talend (Ubuntu) - Read System Variables

Once the tSSH component successfully executes the commands and provided that you have selected the standard output as global variable you could access the value in your next components like this - 

((String)globalMap.get("tSSH_1_STDOUT"))

 

Six Stars

Re: Talend (Ubuntu) - Read System Variables

It was weird but the same code worked fine. I might have missed a little detail somewhere, which I am still unable to figure out. Thanks Abhishek and Rhall. I certainly learnt few more things in the process.