When running Mathematica (v10) on my Raspberry Pi, I'd like to output an image file to a directory other than /home/pi
. I understand that letting Mathematica write files anywhere arbitrarily is a bad idea, but I'd like to be able to send it somewhere other than /home/pi
.
Typically, if I want to write/move/copy a file somewhere I need the sudo
command, but that does not appear to be an option with Export
.
I assume the code should look like the following (to be sent to /dir1/dir2/dir3):
Export["/dir1/dir2/dir3/example.jpg", output, "jpg"]
but this returns an error:
Export::nodir: Directory /home/pi/dir1/dir2/dir3/ does not exist
Export:noopen: Cannot open /dir1/dir2/dir3/example.jpg.
What do I need to do to export my file to an arbitrary directory?
SetDirectory["/dir1/dir2/dir3/"]
and then export normally usingExport["example.JPG", output]
. Does that work for you? $\endgroup$ – DumpsterDoofus Feb 15 '15 at 2:44SetDirectory
. If you have permissions to write in the directory, and it exists, then you can write the file using an absolute path as in your example. You should not be "typically" using sudo. Create the directories you want and give them the permissions necessary outside of Mathematica to allow pi to write to them. $\endgroup$ – Mark Adler Feb 15 '15 at 4:15chmod u+rwx dir
. pi should be the owner for new directories you create for this purpose. If necessary,chown
can be used to set the owner. $\endgroup$ – Mark Adler Feb 15 '15 at 4:53chmod g+rwx dir
. $\endgroup$ – Mark Adler Feb 15 '15 at 4:55