Changing working directory in Erlang shell under Windows
I have开发者_StackOverflow社区 Erlang installed on my WinXP machine. Becouse so, I use it by a "werl.exe". The problem is, that I would like to change a default folder that werl starts in. I cannot find option that would let me do that, although I know there must be something like that. Could anybody help ?
If you want to change directory at run time in the emulator then use the built in function cd as below..
72> cd("c:/Sandbox/erl").
c:/Sandbox/erl
ok
Note: You need to use the forward slash and not backward slash as you would normally do in windows.
You can specify initial settings in a
.erlang
fileIt should be located C:\Program Files (x86)\erlX.X.X\usr.erlang (where X.X.X is the version number...)
If there isn't any then feel create one (note: you'll likely need to run your editor with administrative privileges to create the .erlang file in the appropriate location).
Here is a simple example for the content:
io:format("C:/Program Files (x86)/erl5.10.4/usr/.erlang\n"). io:format(" ______ _ \n"). io:format("| ____| | | \n"). io:format("| |__ _ __| | __ _ _ __ __ _ \n"). io:format("| __| | '__| |/ _` | '_ \\ / _` |\n"). io:format("| |____| | | | (_| | | | | (_| |\n"). io:format("|______|_| |_|\\__,_|_| |_|\\__, |\n"). io:format(" __/ |\n"). io:format(" |___/ \n\n"). shell_default:cd("C:/Documents/MyErlangProjects").
Notice the use of *nix-like forward-slashes (i.e. "/") rather than the typical Windows convention of using back-slashes (i.e. "\").
It can be tested by running an erlang shell and on startup it will print this cool ASCII stuff :). Beware, the cool ascii stuff doesn't mean a valid working directory was specified!
Of course the main important line is the last one:
shell_default:cd("C:/Documents/MyErlangProjects").
where you specify which directory you want to start with as the current working directory.
Enjoy.
Thank you all. It was just as easy as typing a desired path in the "Start in" option in the "preferences" of shortcut to werl.exe.
If you want to run Erlang in many different projects in different directories I found the easiest most basic solution is to create separate .bat
files in each directory. Clicking on one will then run Erlang in the right directory. This makes it easy to set environment variables for Erlang, ERL_LIBS
is a good one. It also makes it easy to use different versions at the same time, one .bat
file for each version.
精彩评论