tFile with relative path

One Star

tFile with relative path

Hello,
To use a relative path in a tFileInput the file must be in the same folder than the script ok. But when I'm lauching the job from TOS, where must the file be ?
e.g. :in my tFileInput i've "context_talend.conf"
Best regards
Ben
Tags (1)
Employee

Re: tFile with relative path

To use a relative path in a tFileInput the file must be in the same folder than the script ok.

No, that's not correct. When using a relative path, the important directory is the current working directory, not the script directory.
I've made a very simple job, with a single tPerl inside it:
use FindBin;
print 'script directory: ', $FindBin::Bin, "\n";
use Cwd;
print 'current directory: ', getcwd, "\n";

and the output is:
Starting job TEMP at 11:13 12/09/2007.
script directory: /home/pierrick/dev/tos/runtime-trunk-eclipse3.3/.Perl
current directory: /home/pierrick
Job TEMP ended at 11:13 12/09/2007.

My advise: always use absolute path. It will make your life easier and happier :-)
One Star

Re: tFile with relative path

you 're right
>>My advise: always use absolute path. It will make your life easier and happier :-)
I try ...
Thanks
One Star

Re: tFile with relative path

Or alternative use a context-variable and evaluate the (absolute) path at runtime.
Employee

Re: tFile with relative path

Or alternative use a context-variable and evaluate the (absolute) path at runtime.

In my opinion, it is more than an alternative, it's a good practice :-)
One Star

Re: tFile with relative path

Or alternative use a context-variable and evaluate the (absolute) path at runtime.

I don't understand how you are doing. Can you explain it ?
One Star

Re: tFile with relative path

Hi bedurand,
the idea is to define a context variable like "rootPath" mas example. If you process any file or execute a command you just expand the context variable and add any relativ information.
Example:
(String)((String)context.getProperty("rootPath")) + "/../../input.xml"
If you call the script from commandline you can set the variable as parameter in the call statement.
One Star

Re: tFile with relative path

What about the portability of this solution ?
My OS is Win XP but the server works with Red Hat.
Can I use File.pathSeparator in the tFile's path ?
Thank you ^^
Employee

Re: tFile with relative path

What about the portability of this solution ?

With Perl, a solution is:
File::Spec->catfile($_context{basedir}, $_context{filepath})