# Why can't an Import[] change $Path? Does anyone know why Import["http://**server**/file.m"] can't make a change to $Path? It seems like file.m can set pretty much any other variable, but not $Path. I suspect Get[] would work, but I can't seem to get Get[] to fetch files over the web. - Possibly a security measure? – Mr.Wizard Jan 17 '13 at 7:59 I'm creating and deleting files and directories in my Imported file, so if it's a security measure it's impressively poorly designed. It feels more like there's some "specialness" to the context that the Import is being evaluated in. – sblom Jan 17 '13 at 15:37 In V9, we made Get take an InputStream, which can be opened from a URL. In reference.wolfram.com/mathematica/ref/Get.html, and where it says "Updated in 9" in the upper right, click "Show changes". – Joel Klein Jan 17 '13 at 15:48 Actually, in V9, Get from a URL string should just work, you don't need to explicitly open a stream. – Joel Klein Jan 17 '13 at 16:32 ## 1 Answer I think \$Path is probably being set in a Block in the Import call. I put this sample code on a server in test.m:

beforePath = $Path; AppendTo[$Path, "d:/tomcat-6.0.35"];
afterPath = $Path; DateString[]  I can see that afterPath has the correct value, but$Path is unmodified.

In[14]:= Import["http://jfkleinlx.wri.wolfram.com/test.m"]

Out[14]= "Thu 17 Jan 2013 09:58:52"

In[19]:= Complement[afterPath, beforePath]

Out[19]= {"d:/tomcat-6.0.35"}

In[20]:= $Path === beforePath Out[20]= True  With V9, to work around this you can open a stream to a URL and use Get as you suspected: In[21]:= st = OpenRead["http://jfkleinlx.wri.wolfram.com/test.m"] Out[21]= InputStream["http://jfkleinlx.wri.wolfram.com/test.m", 133] In[22]:= Get[st] Out[22]= "Thu 17 Jan 2013 10:06:11" In[24]:=$Path === afterPath

Out[24]= True


Remember to Close the stream. Or, you can just Get the URL directly: Get["http://jfkleinlx.wri.wolfram.com/test.m"], which opens a stream internally.

-
That is a lame test.m. You should instead replace the contents with SystemOpen["https://www.youtube.com/watch?v=dQw4w9WgXcQ"] :D –  The Toad Jan 17 '13 at 18:08
That's a good point, here's a stopgap if you are working without Internet: Speak[Uncompress[ "1:eJxVjcENAjEMBFPK0sCVwgMq8BErRAT75IsPpS8KJArwyMPSamc1Pq16ub5DCGc+2JA0S0JVpHwwm‌​jp8W/BnIoTCdfRRXzITcwGZukRQv8g729jOsyc9vuabtZns1HrSuDaeQeVS0F9nHua7/7wfYipCUA=="]‌​] –  Joel Klein Jan 17 '13 at 20:16
There's no way to ninja out of a block, right? –  sblom Jan 19 '13 at 22:53