Hi all, I have to execute python script by tSystem component. Can Talend Studio store the script file .py or only the python code in Metadata or Documentation? I want that both job and script file are stored on Studio and not in a external folder. So, when I export the Job I will not worry about the script file .py thanks all
Maybe you could store the code for the file inside the Job and then during the Job write the code out to a script file, which you then run using the tSystem component and then delete using the tFileDelete. This way you can parameterise the script file and do not need to worry about having files set up wherever you want to run the Job.
You can store the script in a context variable if you like. The String context variables should be able to hold your script. Alternatively you can a tJava component to store the script text in several globalMap key/value pairs. You can use tSetGlobalVar component to interact with the globalMap variable, or interact with it using a tJava component. The code below is how you can store and retrieve String values.... To store.... globalMap.put("MyVarKey", "My text"); To retrieve.... ((String)globalMap.get("MyVarKey")); You can save ANY variable in the globalMap HashMap, hence you need to cast the value on the way out. You can use the retrieval code in tMap components or tFile components for when you want to use it.
I'm not entirely sure you can refer to the Documentation objects at runtime. If you can great, I have learnt something :-) If you can't and don't want to have to manipulate " and ' chars, you could read the file in as a byte array using a tFileInputRaw and output it as a byte array using a tFileOutputRaw component. This is a bit trickier and will require Java convert your types. It will also be meaningless to look at. But won't require any manual manipulation of " and ' chars.
I was being very literal and looking to store the file inside the job. As kzone suggests, it is probably better to store it in a place you can get from anywhere like the cloud. In my previous post I recommended reading the file in as a byte array and writing it out as a byte array. I should have explained that I meant at design time, read it in as byte array. Then store the byte array in a context variable. Then write it out from the context variable after having processed it back into a byte array. This will work as I have done something very similar with image files. But kzone's suggestion is a lot easier and means you can edit your script file without touching the job.