Monday, 29 April 2013

tSystem - How to Execute a Unix or Linux command with Pipe or Redirection

Most of us knows that we can use Talend's in built component tSystem to run windows batch or Linux/Unix commands. However, It doesn't work, when we try to run any Unix or Linux command which includes redirection of output in to file. Talend has provided a work around for executing Unix and Linux with pipe or Redirection.

For Example: Following command to compress the file will not work in tSystem folder.

grep -c abc.csv > mycompressed_abc.gz

To execute a Unix/Linux command having redirection use any of the following methods:

1. Using Single Command: In the component properties of tSystem, enter the following command in the Command text box:
new String[]{"/bin/bash","-c","grep -c abc.csv > mycompressed_abc.gz"}

2. Using Array Command: You can also check "Use Array Command" Checkbox and enter command in the way entered in the screen shot.

3. Last method is to write the Unix or Linux script in a script file and call the script using tSystem component.

e.g. we will create a script with following contents

grep -c abc.csv > mycompressed_abc.gz

enter the following command in the Command text box to execute a script:

"sh -c"

So these are the three methods which which we can run Linux/Unix commands having pipe or redirection in it. Please let me know, if you guys have used any other method. Looking forward for your comments.

You may also like to read..

1 comment:

  1. how to run a script with commandline arguments in talend?