[resolved] Passing variable (context) value from the command line

Highlighted
One Star

[resolved] Passing variable (context) value from the command line

Is it possible to define variable context value from the command line (by the script generated by the export job in TOS).
For example
java -Xms256M -Xmx1024M -cp ../lib/jtds-1.2.jar;../lib/systemRoutines.jar;../lib/userRoutines.jar;.;myjob.jar;../lib; myproject.myjob.MYJOB --context=PROD
--myvariable='TEST'

Accepted Solutions
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

It's ok, it works.
I've passed a parameter to my .bat file an set "--context_param file=%1".

View solution in original post


All Replies
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

hello
yes it is.
Here is an example (with Perl, but Java should be OK) I inserted in a bat file:
"perl" -I"lib" "NPLMATCH%1.job_Jnplmatch.pl" --context=Default --context_param rootDir=%%1 --context_param user=%%2 --context_param password=%%3 --context_param mode=%%4 --context_param backup=%%5 overloads $_context{rootDir} and $_context{user} and $_context{password} and $_context{mode} and $_context{backup}
Highlighted
Employee

Re: [resolved] Passing variable (context) value from the command line

Hello,
I confirm : it's the same in Java.
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

Very good and thanks for your answers.
It would be a good idea to add all these options in the documentation, I don't find them.
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

What is exactly overloads in your example ?
Is it a reserved keywords or just a data ?
Highlighted
Employee

Re: [resolved] Passing variable (context) value from the command line

Another example in java:
--context_param:params_file=/home/stephane/blog/articleContexts/execution/params_prod.csv

The ':' between context_param and params_file is due to a bug in 2.2.1 (don't know if we still have the bug)
Note that any key can be used instead of ':'
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

Hi all!
I have a main job with subjobs (in java with TOS 2.4.1).
One of my subjob read a file.
I want my batch to take in its parameters in the command line the path of this file.
I have in the context of my subjob a context variable for this file and in my command line I've added --context_param file="c:\toto.txt".
But it doesn't work.
Any ideas?
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

Java uses / instead of \
\ is a string escape character which can produce strange effects.
Can you try with --context_param file="c:/toto.txt" and see if it works?
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

Java uses / instead of \
\ is a string escape character which can produce strange effects.
Can you try with --context_param file="c:/toto.txt" and see if it works?

Thanks but it's not the problem.
The context param is not loaded, I've try with --context_param file="toto.txt" ...
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

Hi all!
I have a main job with subjobs (in java with TOS 2.4.1).
One of my subjob read a file.
I want my batch to take in its parameters in the command line the path of this file.
I have in the context of my subjob a context variable for this file and in my command line I've added --context_param file="c:\toto.txt".
But it doesn't work.
Any ideas?

Help!!
Smiley Happy
Highlighted
One Star

Re: [resolved] Passing variable (context) value from the command line

It's ok, it works.
I've passed a parameter to my .bat file an set "--context_param file=%1".

View solution in original post

Highlighted
Two Stars

Re: [resolved] Passing variable (context) value from the command line

Hi Passing the value as a parameter from command line is ok and depicted by many one but how to receive the passed value inside the talend job is pending. Can any one please let us know how to receive the value inside.

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog