Custom telnet Groovy shells – version with shared context

A follow-up to the previous postcustom Telnet shared Groovy shells. This time having shared context for all shells, i.e. shared variables!

The trick was to get Binding object from current Groovy shell Interpreter and pass it in constructor to Groovy shells that we instantiate programmatically on socket connections. Not sure if it’s thread safe BTW (this isn’t production ready (-: ).

The code is based on Groovy Shell internals a bit, so should probably be run only from Groovy shell. (And just in case – I’m using version 1.8.4 of Groovy).

In any case, here’s again some demo video:

UPD: Also there’s the thread-safe version.
In it each shell will have it’s own Binding object, i.e. separate variables context.
But on creating shell we’ll inject two variables into that context:
sharedConcurrentMap – an instance of ConcurrentHashMap which will serve as thread-safe shared context for all shells, and is pre-populated with “server” and “sockets” (the latter are also made thread-safe);
thisShellSocket – a socket that is used for this child shell.

See source code at the end of the post.

As usual, a little demo video:

The source code Continue reading

Windows shell lang neckbreak

Windows Shell Bug Now I have one very good reason to never install anything again in “Program Files (x86)” folder where 64-bit Windows XP usually puts 32-bit apps. The reason is closing bracket character “)” in path, which in combination with “special” behavior of windows cmd.exe shell can (and will) give you a lot of pain in the neck if you do shell scripting (under Win AKA batch scripting). And even if you don’t do shell scripting yourself, some shell scripts that you or any soft you use might need to run, may break.

Continue reading