最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How run a windows console for JavaScript - Stack Overflow

programmeradmin5浏览0评论

I would like to have a console window (a mand line) on Windows 7 which will allow me to play with JavaScript just like a python console.

Update: It's important to have a file access from within the console (or script run through it).

I would like to have a console window (a mand line) on Windows 7 which will allow me to play with JavaScript just like a python console.

Update: It's important to have a file access from within the console (or script run through it).

Share Improve this question edited Dec 23, 2013 at 6:22 andrew.fox asked Dec 23, 2013 at 5:43 andrew.foxandrew.fox 7,9616 gold badges56 silver badges82 bronze badges 2
  • @Blender, you ought to post it as an answer, as it's a good alternative for my reply. – andrew.fox Commented Dec 23, 2013 at 6:04
  • You can run it with Cscript.exe (see How to run .js file from a mand line on windows?) but it is not really practical, also it even more limited that in the browser. – Theraot Commented Dec 23, 2013 at 6:35
Add a ment  | 

4 Answers 4

Reset to default 4

You can use Node.js's REPL. To do so follow this steps:

  1. Download and Install Node.js.
  2. Call Node.js from the Start Menu / Start Screen or directly node.exe installation path (e.g C:\Program Files\nodejs\node.exe).
  3. Enjoy!

You may want to add the installation path to your PATH enviroment variable for ease of use.

Note: to leave node.js press Ctrl + C twice.


To access the local files, you will need the File System module. This is an example of usage:

var fs = require("fs");
fs.readFile(
    "C:\\test.txt",
    function(err, data)
    {
        if (!err)
        console.log(data.toString());
    }
);

This will output the contents of the file C:\test.txt to the console.

Note: An unhandled exception will cause node.js to "crash".

You can just use the developer tools.

For example, in Chrome, press F12. This will bring up the developer tools. The last option on the menubar is console. This will allow you to create JS variables and functions and to interact with DOM elements on the current page

It's possible thanks to Mozilla Rhino JavaScript Engine.

To create a console window for JS:

1) Download Mozilla Rhino JavaScript Engine binary.

2) Extract: js.jar.

3) Create a script to run the console window (e.g. rihno_console.bat):

java -cp js.jar org.mozilla.javascript.tools.shell.Main

For more information about usage (for instance, and global functions inside this console) visit the Rhino Shell web page.

Just like I informed another user with the same question as yours who was faced with the same need, check out DeskJS (https://deskjs.wordpress.). It's a portable Windows console application that lets you run pure JavaScript code and even load any existing JS files. It supports even the basic JS popup boxes implemented in browsers. You can save your mands as JS files that can be run on startup or by dragging-and-dropping them on the app. Plus there's so much more to it like you can create a build system for Sublime Text that can run JS files via cmd, it supports themes for customizing the entire console and snippets which let you save short snippets of JavaScript code for later use. Improvements are still being made on the app together with other native APIs being included. Hope this helps you as it did for me.

发布评论

评论列表(0)

  1. 暂无评论