Windows tricks for erlangers

Not that I spend much time compiling erlang code in Windows (unless I’m using cygwin or coLinux), but the issue does pop up from time to time. Here are a few minor tricks that can help a bit.

Starting Erlang in the current directory
For a unix user, it’s of course odd that this should be a problem.

John Hughes used a nice trick that’s so simple that I slap myself for not having thought of it: Right-click on a .beam file, select “Open With…” and locate werl.exe. Now you can open an erlang shell in the current working directory by double-clicking a .beam file.

Modifying the Windows context menu
So what if you don’t have any .beam files, and you’re trying to get to an erlang shell
in order to create some?

I did some googling and found this tutorial on youtube on how to add custom entries to the context menu.

It seemed simple enough, but Vista still served me a few hours of utter confusion since it took what I inserted, and then copied it to another place in the registry (without letting me know)… but only the first time. My changes and additions were simply ignored. The solution? Search the registry for the key you inserted, and you’ll figure out where Vista wants it to be, then make your changes there.

What I’ve experimented with so far is to add under Computer\HKEY_CLASSES_ROOT\ErlangSource\shell\ the following entries:

Compile with erlc
- Command = "C:\Program Files\erl5.6.3\bin\erlc.exe" "%1"
Make all
- Command = "C:\Program Files\erl5.6.3\bin\werl.exe" "-make"
Erlang shell
- Command = "C:\Program Files\erl5.6.3\bin\werl.exe" "%1"

A problem with running erlc this way is that the window is destroyed immediately upon completion. I’ve poked around a bit for good workarounds. One option is of course to write an erlang function that compiles the file, then either sleeps a short while, or waits for input.

6 thoughts on “Windows tricks for erlangers

  1. For command-line shells, consider using the prefix ‘cmd /k’, followed by the rest of your erlc command. Cmd is the command shell; /k makes it run the following arguments as a command but *not* exit the shell.

    Alternatively, write a batch file that looks like:

    @echo off
    \erlc %*

    And pass it all the arguments for erlc. It will pause with “Press any key to continue…” before dismissing the window.

  2. Thanks. Yes, I did try ‘cmd /K’, but apparently, cmd.exe doesn’t like spaces in the following command, even if it’s enclosed within double quotes. I had an alternative path without spaces, but apparently, it doesn’t like symlinks either… :)

  3. I use the following small batch file which I liberally sprinkle in the directories where I work. I can just click on these to start an erlang in the current directory. Setting ERL_LIBS means that erlang will find my own and imported libraries which are not part of the distribution.

    @echo off

    rem Use my git directories as libraries
    set ERL_LIBS=C:/msys/1.0/home/GameStudio/erlang

    start “Erlang” “C:\Program Files\erl5.6.5\bin\werl.exe”

  4. Cmd’s quoting rules, like Windows’ quoting rules, are odd and seemingly ill-defined. The quotes can nest almost magically, though.

    Consider an application called ‘test me.exe’ in the current directory which prints out the number of command-line arguments (aside from the executable name). The following runs are possible:

    cmd /k “test me”

    Runs “test me”, and prints 0.

    cmd /k “”test me” foo bar”

    Runs “test me”, and prints 2.

    cmd /k “”test me” “foo bar””

    Runs “test me”, and prints 1.

    This behaviour is the same whether or not cmd /k is invoked from the command line, or from e.g. a shortcut. For example, the last example above, as a command line, looks like the following on my system:

    %windir%\system32\cmd.exe /k “”c:\cygwin\home\barrkel\test me.exe” “foo bar””

    The extra level of quoting makes it problematic for expanding argument lists like %*, though, so you’d need to build it up out of shift etc. when writing a batch file.

  5. @Barry: well, that would explain it. (:
    When calling cmd from the registry, the command and arguments are given separately, so I don’t think double quoting will interfere with the %1, but I’ll give it a try when I get back to my own machine.

  6. I’m not an Erlanger yet, I plan though to learn it, but I can share the way I execute something in a certain directory. I’m using Total Commander which has a command line at the bottom. Simply enter cmd right there, press enter and then you may execute any program you wish. Well, it must be on the PATH though.

Leave a Reply

Your email address will not be published. Required fields are marked *