On Jan 14, 12:27 pm, Michael <[EMAIL PROTECTED]> wrote: > I am trying to find a way to reliably get the path to currently > executing script file, from within that same file. Reason for that is > I want to access some other files that I know are in the same > directory as the script file, but I can't predict what the current > working directory will be when my script is run.
I have wanted to do this in the past as well, but I am pretty sure you have to build this into your own embedding (or launch mechanism) if you want to do it. I don't use the Rhino shell much, but in my own embedding I've had to wrestle with this issue from several perspectives (and am thinking that a "module" loading strategy in which the entry point of the module is provided a context from which to load contained files is the next step after the series of ad hoc solutions I've used thus far). There are good reasons you can't do it -- because it's legal to load code for Rhino from any Java Reader. As such, the Rhino codebase doesn't really have the concept of a "file" from which JavaScript code is loaded (it can also evaluate strings -- as you have probably seen from the shell, you can pass arbitrary code on the command line). So the question of which file JavaScript code was loaded from would not have a general answer and code from the file system would need to be handled as a special case. But what if you are (like many) using Rhino on the server side; clearly you'd like to be able to load code by relative path from other code, even though you didn't load it from a "file" (but rather a ServletContext). So anyway, as I understand them, the issues here end up being more complex than one might think at first glance. Others more familiar with the Rhino shell may have more to add. -- David P. Caldwell http://www.inonit.com/ _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
