Run JavaScript in Windows

前端 未结 5 880
一个人的身影
一个人的身影 2021-02-14 06:21

I thought for some simple tests that just run a few commands i would try using some JavaScript and run it from the command line in Windows XP.

So for a quick test I crea

5条回答
  •  遥遥无期
    2021-02-14 07:01

    A good approach is to redirect all of the usual output like in a following examples. It will allow you to test JavaScript designed for web without needing to rewrite.

    test.js

    var console = {
        info: function (s){
            WSH.Echo(s);
        }
    }
    var document = {
        write : function (s){
            WSH.Echo(s);
        }
    }
    var alert = function (s){
        WSH.Echo(s);
    }
    
    console.info("test");
    document.write("test2");
    alert("test3");
    

    You can call the script like this:

    Cscript.exe test.js firstParam secondParam
    

    which will give you:

    test
    test1
    test2
    

提交回复
热议问题