Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
INESBK
Creator
Creator

how to execute a python script file with an argument using tSystem

Hello, 

i created this job tFileList------->tSystem------------>tExtractDelimetedFields

in order to iterates on files and folders with tFileList, get ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH")) as result and use this result in tSytem as argument to my script Python.

rq : my script python  allow me to read DBF file.

I used this command : "python \"liredbf.py" + ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH")) but i got this error 

python: can't open file 'liredbf.py null': [Errno 2] No such file or directory 

How can i get the result of tFileList to use it as argument for my Script Python.

 

Thank you in advance
cordially.

Labels (3)
1 Solution

Accepted Solutions
vapukov
Master II
Master II

ok, and on original post, and on picture - I saw wrong name of variable

 

correct - 
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

on picture and in original post -
((String)globalMap.get("tFileList_1__CURRENT_FILEPATH"))

 please double-check

 

it also my mistake, because I copy past from Your post, but this is could be reason for NullPointer error

View solution in original post

13 Replies
vapukov
Master II
Master II

generally You can test:

 

 

"python \"liredbf.py\" " + ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH")) 

look for close \"and space after liredbf.py 

 

 

or You can switch mode of tSystem to Use Array and pass each parameter as separate line

0683p000009LthJ.png

also You can omit open and close \" (not sure, but usually they need only if filename with space)

INESBK
Creator
Creator
Author

Thanks vapukov for your response. 

I try to do the second solution, i don't get an error but also i don't get any result. 

context.PathPython is: "python \"C:\\Users\\Ines\\Desktop\\Python\\lirealldbf.py"

context.var is : ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH"))

i do this test 0683p000009Lu8R.png0683p000009Lu8z.png

I think my script python can't read this path ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH")) so it can't open the file ! 

 

vapukov
Master II
Master II

it wrong construction

 

try this - first without any context variables 

row by row

 

1) "python"
2) "C:\\Users\\Ines\\Desktop\\Python\\lirealldbf.py"
3) ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH"))

 

or 

1) "cmd"
2) "/c"
3) "python" 4) "C:\\Users\\Ines\\Desktop\\Python\\lirealldbf.py" 5) ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH"))

I do not have access today for windows Talend Studio and not remember it accept first variant or not (on mac I use 1st)

 

also - check is python in path or not - when windows start new process for tSystem, it is not fact all PATH variables will be passed, so try to add full path to Python

 

INESBK
Creator
Creator
Author

I've changed my construction but i got this error :

Exception in component tSystem_1
java.lang.NullPointerException
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at local_project.secondtest_0_1.SecondTest.tFileList_1Process(SecondTest.java:1097)
at local_project.secondtest_0_1.SecondTest.runJobInTOS(SecondTest.java:2284)
at local_project.secondtest_0_1.SecondTest.main(SecondTest.java:2132)
2017-05-11 10:42:22|Kc8fjP|Kc8fjP|Kc8fjP|LOCAL_PROJECT|SecondTest|Default|6|Java Exception|tSystem_1|java.lang.NullPointerException:null|1
[statistics] disconnected 

 

In my code Python i wrote this path f1 =sys.argv[1] to read the file as an argument and i got a result when i execute my script python on command ligne but with talend doesn't work ! 

 

vapukov
Master II
Master II

show the current pictures

INESBK
Creator
Creator
Author

Here is the picture 

0683p000009Ltes.png

vapukov
Master II
Master II

please add - what in tSystem settings?

INESBK
Creator
Creator
Author

0683p000009Lu9O.png

And i tried this version but usually the same error 

1) "cmd"
2) "/c"
3) "python" 4) "C:\\Users\\Ines\\Desktop\\Python\\liredbf.py" 5) ((String)globalMap.get("tFileList_1__CURRENT_FILEPATH"))

 

vapukov
Master II
Master II

ok, and on original post, and on picture - I saw wrong name of variable

 

correct - 
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

on picture and in original post -
((String)globalMap.get("tFileList_1__CURRENT_FILEPATH"))

 please double-check

 

it also my mistake, because I copy past from Your post, but this is could be reason for NullPointer error