Javascript execution using tsystem

Six Stars

Javascript execution using tsystem

Hi all ,

I have a javascript file that contains a function which returns a value. I want to call the function from any talend component, get the returned value and use it in the job .I tried the same using tsystem component but i did not know how to call the js function from the tsystem command .Please help me on this.

 

Thanks in advance,

Praveen M.

Forteen Stars

Re: Javascript execution using tsystem

generally - same as You run it from command line 

 

for example in case of windows 

it will be

"cmd /c cscript your file.js"

 

in case of Mac it will be

"rhino yourfile.js"
or
"node yourfile.js"



-----------
Six Stars

Re: Javascript execution using tsystem

Hi ,

 

Thanks. Am able to run the js file using the command in tsystem as u mentioned , but my issue is to return a value from the js function to any other component or job in talend. I used "echo" statement to throw the value , it worked .But i want to get the return value from the js function into my talend job.

 

Thanks in advance ,

Praveen M.

Forteen Stars

Re: Javascript execution using tsystem

tSystem have settings for store Standard Output and Error Output - Console and/or variable

 

Enable store to variables, and in case of standard output - check 

((String)globalMap.get("tSystem_1_OUTPUT"))

 

-----------
Six Stars

Re: Javascript execution using tsystem

Thanks. I used ,

System.out.println((String)globalMap.get("tSystem_1_OUTPUT"))

in tjava component after writing the necessary file details in tsystem , it thrown me 'null'. Can you elaborate the method to get the value from js file a bit in detail ?  

 

Thanks ,

Praveen M.

Six Stars

Re: Javascript execution using tsystem

 

function test(){
var getValues = WScript.Arguments; return "The merged values are:"+getValues(0)+"-"+getValues(1)+"."; } test();

This is the sample code on my JS file .

"cmd /c cscript samplefile.js \"test\" \"run\""

This is the code on my tsystem .

 

Thanks ,

Praveen M.

 

 

 

Thanks ,

Praveen M.

Forteen Stars

Re: Javascript execution using tsystem

Screen Shot 2017-04-19 at 9.04.57 PM.png

 

this is execution of You example in windows CMD shell

Why You expect anything other than null, if Your script return null :-)

 

tSystem catch output, but Your script do not have it

-----------
Six Stars

Re: Javascript execution using tsystem

I have checked the option to store the tsystem output to global variable , still it throws null. If my method throws null ,what is the correct method to store the tsystem's output in a variable and how to use it in tjava or any other component ? Thanks , Praveen M.
Forteen Stars

Re: Javascript execution using tsystem


@praveenvm wrote:
I have checked the option to store the tsystem output to global variable , still it throws null. If my method throws null ,what is the correct method to store the tsystem's output in a variable and how to use it in tjava or any other component ? Thanks , Praveen M.

You have some misunderstanding - Your function return information into main part of Your script, but Your script do not return anything to OS console!

 

tSystem store into variable or on console - Standard or Error Outputs

So for store something need to have this something :-)

 

 

My picture it is result run of Your script without talend - just under windows command line ... 

because Your script do not send to Output any information ( == print), Talend nothing to store into variable

-----------
Six Stars

Re: Javascript execution using tsystem

Thanks , i understand it now.

So how should i write to OS Console from my .Js file ?

I tried using echo , it does not work. Also what should be the code on t_java component to get the value from .js file

 

Thanks ,

Praveen M.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download