One Star

[resolved] How do i pass a String parameter with space to shell file from talend?

Hi,
I have a shell file test.sh where i just do echo "$1", when i pass parameter String with spaces for e.g 'a b c' through command prompt it displays a b c, but when i try to call the same shell file through talend's tSystem component in the same way saying "sh ./test.sh 'a b c' " it displays only 'a .
This is a very basic requirement while we pass context parameters. So, i am sure there must be a solution to this. I have tried using the escape character '\' before the single quotes but no help.
Any help will be really appreciated.
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

Hi,
I've tested this and found another way to pass these paramters containing white spaces. The following worked for me when I entered it inside Commdn parameter of a tSystem component:
new String[] { "./test.sh", "a b c" }
Why? Because the Runtime.Exec function that is called by Talend can handle a String array as parameter as well, instead of a normal String. Any extra parameters can be added as desired.
Hope this helps.
Regards,
Arno
7 REPLIES
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

In other words, how do i pass a String with spaces as a single parameter to a shell file triggered from the tSystem component in linux OS?
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

Hi
I find a topic which is related to this issue Will tSystem function with spaces?.
Regards,
Pedro
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

Hi
I find a topic which is related to this issue Will tSystem function with spaces?.
Regards,
Pedro

Hi,
That issue says to put the tSystem command into a shell file and then call the shell from tSystem.
I am also calling a shell from tSystem, but the problem is while passing parameters to that shell file. It seems one cannot pass a String parameter with spaces to a shell file.
Regards,
Diwakar
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

Hi,
I've tested this and found another way to pass these paramters containing white spaces. The following worked for me when I entered it inside Commdn parameter of a tSystem component:
new String[] { "./test.sh", "a b c" }
Why? Because the Runtime.Exec function that is called by Talend can handle a String array as parameter as well, instead of a normal String. Any extra parameters can be added as desired.
Hope this helps.
Regards,
Arno
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

Hi,
I've tested this and found another way to pass these paramters containing white spaces. The following worked for me when I entered it inside Commdn parameter of a tSystem component:
new String[] { "./test.sh", "a b c" }
Why? Because the Runtime.Exec function that is called by Talend can handle a String array as parameter as well, instead of a normal String. Any extra parameters can be added as desired.
Hope this helps.
Regards,
Arno

Hi Arno,
Great!!! That worked perfectly for me as well.
But then how do we pass integer values to the String array?
Regards,
Diwakar
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

Hi Diwakar,
I think you can pass integers like this:
new String[] { "./test.sh", String.valueOf(12), String.valueOf(1) + " " + String.valueOf(1) }
This should run the test script with the following commandline:
./test.sh 12 '1 1'
Best regards,
Arno
One Star

Re: [resolved] How do i pass a String parameter with space to shell file from talend?

Yes, that worked too. Thanks Arno.
Regards,
Diwakar