How do you use a context variable in tSystem component?

Nine Stars

How do you use a context variable in tSystem component?

I have two context variables which are assigned values:
context.oldFileName
context.newFileName
I want DOS to rename the old file name with the new file name.
I think my tSystem component Command should look something like this:
"cmd /c echo "+ context.oldFileName+ context.newFileName+" "
or this:
cmd /c REN %oldFileName% %newFileName%
When I run the Command "cmd /c echo "+ context.oldFileName+ context.newFileName+" "
The result is "nullnull"
How do I get the tSystem to know the values of context.oldFileName and context.newFileName?
Seven Stars

Re: How do you use a context variable in tSystem component?

I think the problem is not with tSystem itself (since that command works fine for me) but with some other aspect of your job design. How do you assign the context variable values? Can you print them with tJava or tContextDump? Screenshot your job...
Five Stars

Re: How do you use a context variable in tSystem component?

It does sound like a variable assignment issue.
Don't forget that Talend provides components to do this type of stuff tFile* which is preferable to dropping out to the OS
Four Stars

Re: How do you use a context variable in tSystem component?

Hi
Try this code for me it is working fine:
"cmd /c ren " +context.oldfile+ " "+context.newfile

thanks
Anil Kumar Burri
http://anilkumarburri.wordpress.com/
Nine Stars

Re: How do you use a context variable in tSystem component?

Here is my current tSystem code:
"cmd /c REN %oldFileName% %newFileName%"
The job runs without errors, but the files aren't being renamed, the file names stay the same:

Starting job FileRename at 11:02 15/07/2013.

connecting to socket on port 3659
connected
tContextLoad_1 set key "oldFileName" with value "test1.txt"
tContextLoad_2 set key "newFileName" with value "test1new.txt"
tContextLoad_1 set key "oldFileName" with value "test2.txt"
tContextLoad_2 set key "newFileName" with value "test2new.txt"
tContextLoad_1 set key "oldFileName" with value "test3.txt"
tContextLoad_2 set key "newFileName" with value "test3new.txt"
disconnected
Job FileRename ended at 11:02 15/07/2013.
Seven Stars

Re: How do you use a context variable in tSystem component?

Screenshot your job
Nine Stars

Re: How do you use a context variable in tSystem component?

Here
Seven Stars

Re: How do you use a context variable in tSystem component?

Can't see anything obvious wrong but it's certainly an unusual design. Would need more info on what you're trying to do in each component but have you tried using an Array Command in tSystem?
Nine Stars

Re: How do you use a context variable in tSystem component?

I am trying to clean out weird characters from the files names, such as these characters "!@#$%&()-_+" and I want to remove any periods except the file extension tag.
I am doing the filename clean up in the tMap. For example to get rid of the @ sign I use:
row3.fileName.replaceAll("@","").trim()
One Star

Re: How do you use a context variable in tSystem component?

Hi,
I simulate a simple one like
Fileinputdelimited-->contextload-->system
with code
"cmd /c ren "+context.oldfile+" "+context.newfile

it works fine. And name of file changed.
i think that you should try to put tsys in the end of this job.
like onsubjectok of tfilelist? or use tpostjob?
because in the screen shot i saw tcontextload for filepath ran faster than the others and you connected it to tsys. so...
Try it
Five Stars

Re: How do you use a context variable in tSystem component?

Why not just use tFileCopy?
It supports rename and keeps everything 'talend' and is cross platform.
One Star

Re: How do you use a context variable in tSystem component?

Don't forget that Talend provides components to do this type of stuff tFile* which is preferable to dropping out to the OS
Nine Stars

Re: How do you use a context variable in tSystem component?

tFileCopy would take a long time to run for large files.
It looks like my job is getting the values but its failing on the tSystem:
The system cannot find the file specified.
tContextLoad_1 set key "newFileName" with value "#$%&-_+.txt"
tContextLoad_1 set key "newFileName" with value "BatchFile.bat"
tContextLoad_1 set key "newFileName" with value "testFile.txt"
.-----------+-------------+-----------+---------------.
| tLogRow_1 |
|=----------+-------------+-----------+--------------=|
|key2 |value2 |key |value |
|=----------+-------------+-----------+--------------=|
|newFileName|#$%&-_+.txt |oldFileName|!@#$%&()-_+.txt|
|newFileName|BatchFile.bat|oldFileName|BatchFile.bat |
|newFileName|testFile.txt |oldFileName|testFile.txt |
'-----------+-------------+-----------+---------------'
Seven Stars

Re: How do you use a context variable in tSystem component?

So are the values getting to tSystem now? Have you tried just echoing them?
Is the path correct? Try just the "cd" command to check what path tSystem thinks it's in.
Nine Stars

Re: How do you use a context variable in tSystem component?

Not sure why it works, but it does!
I ended up putting Iterate from the tFileInputDelimited to the tSystem.
This is the tSystem command that worked for me:
"cmd /c ren \""+context.oldFileName+"\" \""+context.newFileName+"\""