App won't write to file when run from Finder (ok in Xcode)

梦想的初衷 提交于 2019-12-12 02:06:20

问题


I have created an osx app that runs perfectly in Xcode but not from Finder window. It reads a binary data file and outputs two simple text files and displays some graphics. Since it works in Xcode, I copy the app file to say Applications directory along with the binary input file. The binary file can be read okay. The two text files cannot be opened for writing (permission denied) and so the program exits. When run from Xcode, there is no problem writing the two text files in the Applications directory.

I have checked the permissions for the text files and they are read/write for my username and group (staff) both from unix terminal ls -al and Finder get info.

So it appears that the app cannot open any file for writing in the Applications directory when double clicked from Finder window.

I have tried several directory locations for the app and the binary input file without success.

/Users/person/Library/Application Support/MyApp /Users/person/Applications/MyApp

None work when started from Finder, but all work from Xcode.

The working directory is / when started from Finder, but the program changes it at startup to the appropriate directory.

This problem has got me beat. I’ve run out of ideas. Any help would be appreciated.


回答1:


Full path names resolves all issues with running from Finder. Multiple directory locations were tried successfully. Awesome thanks to Paul R.



来源:https://stackoverflow.com/questions/26149445/app-wont-write-to-file-when-run-from-finder-ok-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!