One Star

How to use external parameters in scripts generated

I have developped a job that transform a delimited file in an other.
I would like to run the job with the script generated and an input file as a parameter on the command line or in an environment variable.
I assume I have to use context, but I can't find how to modify the value of the variable defined in the context.
Tags (1)
8 REPLIES
Community Manager

Re: How to use external parameters in scripts generated

Hi,
In the Context definition view, check the Prompt box facing your parameter and in Prompt Message, type in the relevant question reminding you to change the value.
Find further information about Contexts and Variables use in Talend Open Studio User's Guide 0.6.
HTH.
One Star

Re: How to use external parameters in scripts generated

Hi,
Thank you for the quick answer. I have reread the User Guide about context and make some experiments with the demo job "IfOkIfError" and I did not see how to define the input file in parameters.
First If I have used the Prompt check box as you requested. If works when I run the job under the studio by prompting a question box. But nothing appears when I run the script generated (I have reregenerated the job).
Examining the scripts I have seen that the run.bat command contains the line:
D:\NIP\PERL\bin\perl.exe TALENDDEMOS.job_ifOk_ifError.pl --context=TALENDDEMOS.job_ifOk_ifError_Default.pl
The context is a file given in parameters and contains:
$_context{filepath} = 'D:\NIP\FTP\INPUT\demo.csv';
The path is a constant value and I would like to have a parameters. I am not familiar with perl and I don't know how to do that.
I could manage to generate a new context file each time I want to use the script.
Frederic
Employee

Re: How to use external parameters in scripts generated

I would like to run the job with the script generated and an input file as a parameter on the command line or in an environment variable.

Very interesting ideas.
Using a parameter on the command line would ask a small development, I've juste created 634, monitor it to be notified of its resolution.
Second solution would be to use an environment variable, as you suggest. Fill the context parameter value as $ENV{input_directory} if you want to use the environment variable "input_directory" as context variable.
Another way to do it is to use the tContextLoad 538 (not resolved yet).
Employee

Re: How to use external parameters in scripts generated

The "prompt" checkbox in context management is a GUI (Graphical User Interface) option. It is unknown when the script is run outside the studio.
A solution can be to write another context file and use it a command line execution.
One Star

Re: How to use external parameters in scripts generated

Thank you Smiley Wink
putting $ENV{input_file} in the context works perfectly (tested under windows but should be easier to use under linux).
It allows me to run the jobs in batch mode with an external scheduler with files given by this scheduler. Meanwhile you adds the new features I will use Env variables.
One Star

Re: How to use external parameters in scripts generated

When i have defined a parameter, how can i retrieve it in an expression
Employee

Re: How to use external parameters in scripts generated

When i have defined a parameter, how can i retrieve it in an expression

If this a context parameter, in any property text field you can use auto completion with CTRL+space to have a list of context and global variables.
One Star

Re: How to use external parameters in scripts generated

Thank you Smiley Happy