Hi all, I have a little ruby script that accepts a file name as a
parameter. Given the company standards, the script has to be deployed on
a specific “bin” folder. It has a cryptic name so a more “human” symlink
was created on the same folder, let’s call it “run_process”. I ended up
with something like this:
The “some_path/bin” appears on the path of the user but every time he
runs the script he has to provide the expanded file name otherwise the
script will try to find the file on some_path/bin folder.
Is there a way to avoid this by just executing “run_process my_file” ?
Hi all, I have a little ruby script that accepts a file name as a
parameter. Given the company standards, the script has to be deployed on
a specific “bin” folder. It has a cryptic name so a more “human” symlink
was created on the same folder, let’s call it “run_process”. I ended up
with something like this:
So you have a symlink “run_process” which points to
“cryptic_ruby_script.rb” in the same directory?
The “some_path/bin” appears on the path of the user but every time he
runs the script he has to provide the expanded file name otherwise the
script will try to find the file on some_path/bin folder.
Is there a way to avoid this by just executing “run_process my_file” ?
I am not sure I understand your problem. Since the symlink and the real
file reside in the same directory all relative paths must work properly.
If you want to just use the file name, then you need to add a directory
to get the full path. I have no idea how that directory is defined,
i.e. is it relative to the binary, is it a system fixed directory etc.?
Please fill in the missing information.
In the meantime you can experiment with File.readlink for reading
symlinks.
Thanks Robert. It’s curious, I don’t do any chdir on my code. But you
have given me a clue of why my code is not working properly. I will send
an update tomorrow if it works.
I hope things are more clear now.
Yes. The error must be in your script. As long as you do not change
the current directory (e.g. via Dir.chdir) the relative path works
properly. I can think of at least these two solutions:
remember the proper location by converting the relativ path to an
absolute path using File.expand_path before you chdir.
open the file before the chdir.
completely get rid of the chdir.
What is best depends on your script which you did not provide.
Cheers
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.