如果你不想安裝任何外部工具,您可以使用Windows內置的Cscript.exe和短腳本來讀取/ EVAL /打印/循環如下:
try {
throw {};
} catch(repl) {
while (repl.line != '.exit') {
if (repl.line) {
repl.err = null;
try {
repl.out = eval('(' + repl.line + ')');
} catch (e) {
if (e instanceof SyntaxError) {
try {
repl.out = eval(repl.line);
} catch (e) {
repl.err = e;
}
} else {
repl.err = e;
}
}
if (repl.err) {
WScript.stdout.writeLine('Error: ' + repl.err.message);
} else {
WScript.stdout.writeLine(repl.out == null ? String(repl.out) : (typeof repl.out.toString == 'function' ? repl.out.toString() : Object.prototype.toString.call(repl.out)));
}
}
WScript.stdout.write('> ');
repl.line = WScript.stdin.readLine();
}
}
保存,作爲repl.js並運行cscript repl.js
以獲得類似於jsc的控制檯。
好問題,但接受的答案實際上並沒有回答它。 cscript,正如phpied.com上的鏈接所建議的那樣,不是交互式的。犀牛殼無法訪問操作系統資源(文件,網絡,管道等)。 – 2011-05-07 12:50:43