Search code examples
javaprintingtalend

tJava fetch string from print output in talend


currently I found an alternative to fetch the string output in Java using Talend Studio:

tJava code:

String output=((String)globalMap.get("tSystem_1_OUTPUT"));

System.out.println("Printing the error code 1 : "+StringUtils.substringBetween(output,"source count:", "destination count:"));

tJava output:

Printing the error code 1 : ', '1000')
('

enter image description here

Expected Result:

Printing the error code 1 : 1000

However, tJava takes the result exactly between string " source count:' " and " destination count: ", so that included the bracket and all. The expected result is only to get the value 1000.

How do I apply this java code to fetch the correct output?


Solution

  • Haven't test this within Talend itself but try this ...

    String output=((String)globalMap.get("tSystem_1_OUTPUT"));
    var sourceCount = output.split("\\)")[0].split(",")[1].replace("'", "").trim();
    
    System.out.println("Printing the error code 1 : " + sourceCount);