larsch / ocra

One-Click Ruby Application Builder
http://ocra.rubyforge.org/
833 stars 84 forks source link

Ocra doesn't change the working directory #106

Closed aksun1 closed 8 years ago

aksun1 commented 9 years ago

I have these lines on top of my Ruby code, and tried multiple combinations but none of them have worked. I also have tried --chdir-first but it had no effect.

$:.unshift File.dirname($0)
Dir.chdir(File.dirname($0))

I have a config file that is in the same directory than the exe created by Ocra. The file is loaded by this:

cnf = YAML.load_file('config.yml')

However, the file doesn't load from the same directory as wanted. The error, I think, tells it tries to load it from the temporary directory when the exe runs.

error

How can I get the script load the config.yml file from the same directory than the exe?

larsch commented 9 years ago

As of current, I don't know of a way to know the directory of the executable. If the executable is clicked in Windows Explorer, or launched via a shortcut, the current directory should be the directory of the executable, and it should not be necessary to to chdir() anywhere to read a file in the same directory.

If launched via command line, or a shortcut with a modified starting directory, I'm not sure there's currently a way to know where the executable exists.

aksun1 commented 9 years ago

I'm trying to start the program through the explorer. What could be the reason it tries to open the config file from the temp directory then?

larsch commented 8 years ago

From the README: