In Windows, you can run this file from the command prompt in cscript.exe, and it provides an simple interactive shell. No completion.
// shell.js // ------------------------------------------------------------------ // // implements an interactive javascript shell. // // from // http://kobyk.wordpress.com/2007/09/14/a-jscript-interactive-interpreter-shell-for-the-windows-script-host/ // // Sat Nov 28 00:09:55 2009 // var GSHELL = (function () { var numberToHexString = function (n) { if (n >= 0) { return n.toString(16); } else { n += 0x100000000; return n.toString(16); } }; var line, scriptText, previousLine, result; return function() { while(true) { WScript.StdOut.Write("js> "); if (WScript.StdIn.AtEndOfStream) { WScript.Echo("Bye."); break; } line = WScript.StdIn.ReadLine(); scriptText = line + "\n"; if (line === "") { WScript.Echo( "Enter two consecutive blank lines to terminate multi-line input."); do { if (WScript.StdIn.AtEndOfStream) { break; } previousLine = line; line = WScript.StdIn.ReadLine(); line += "\n"; scriptText += line; } while(previousLine != "\n" || line != "\n"); } try { result = eval(scriptText); } catch (error) { WScript.Echo("0x" + numberToHexString(error.number) + " " + error.name + ": " + error.message); } if (result) { try { WScript.Echo(result); } catch (error) { WScript.Echo("<<>>"); } } result = null; } }; })(); GSHELL();
If you want, you can augment that with other utility libraries, with a .wsf file. Save the above to "shell.js", and save the following to "shell.wsf":
<job> <reference object="Scripting.FileSystemObject" /> <script language="JavaScript" src="util.js" /> <script language="JavaScript" src="shell.js" /> </job>
...where util.js is:
var quit = function(x) { WScript.Quit(x);} var say = function(s) { WScript.Echo(s); }; var echo = say; var exit = quit; var sleep = function(n) { WScript.Sleep(n*1000); };
...and then run shell.wsf from the command line.