Current directory is lost on OSX (and Windows?)

34 views
Skip to first unread message

Matthijs Kooijman

unread,
Apr 9, 2014, 5:16:32 PM4/9/14
to devel...@arduino.cc
Hey folks,

when running arduino from the commandline, users expect the current
directory to be used when resolving relative paths. That is,

arduino --verify Blink.ino

is expected to look for Blink.ino inside the current directory, not
somewhere else.

On Linux, the arduino wrapper script changes directory before starting
java, which breaks this. This was fixed by making the wrapper script
pass the original directory to the java code using the --curdir option:

https://github.com/arduino/Arduino/commit/d133365cc17ed6e814ded79522368a0ecda4ed0d

However, it seems that on OSX, this same problem occurs. Looking at the
error output, it seems that the current directory is set to
/Applications on startup. However, OSX does not have a wrapper shell
script, but an opaque JavaApplicationStub binary blob (which I think
takes its instructions from the Info.plist file). Looking at the error
output, the working directory is changed to /Applications.


Any idea how we can make this work? Looking at [1], it seems there is a
WorkingDirectory property for Info.plist, but I'm not sure how to
specify "don't change the directory...

[1]: https://developer.apple.com/library/mac/documentation/java/Reference/Java_InfoplistRef/Articles/JavaDictionaryInfo.plistKeys.html

Anyone have any idea how / if this works on Windows?

See also: https://github.com/arduino/Arduino/issues/1493

Gr.

Matthijs
signature.asc

Matthijs Kooijman

unread,
Apr 25, 2014, 4:34:12 PM4/25/14
to devel...@arduino.cc
Hey folks,

any comments on this issue? I looked a bit further and on OSX, it seems
the JavaApplicationStub always changes the current directory, no matter
what. See also:

http://lists.apple.com/archives/java-dev/2007/Mar/msg00125.html

Given this, I propose to add a wrapper shell script for OSX too. The
idea is that:
1. The wrapper script adds --curdir to the commandline
2. Then calls the JavaApplicationStub
3. The regular startup through the GUI can still use the
JavaApplicationStub directly.

So the wrapper script is only minimal (unlike the Linux version, which
also handles the directory changing and setting up the java
environment). Alternatively, we could remove the JavaApplicationStub
altogether and use a more featured wrapper script like on Linux, but I'm
not sure what JavaApplicationStub does exactly.



On the Windows side, Arduino is started through launch4j. Looking at the
docs, it seems it has a "chdir" configuration that Arduino sets to ".",
meaning change to the directory containing arduino.exe.

http://launch4j.sourceforge.net/docs.html

We could remove the "chdir" from the configuration, which I _think_ will
leave the directory unchanged. However, I suspect that then there is no
longer any way to find out where arduino.exe (and thus find out where
the data files are).

So, I'd propose _also_ adding a wrapper script (.bat?) for Windows,
which essentially does the same thing as the OSX version I just
suggested.


If this sounds ok to people, I might have a go at implementing this
(though I'd have to find someone to test the OSX stuff, since I don't
have that).


Gr.

Matthijs
signature.asc
Reply all
Reply to author
Forward
0 new messages