windows command line javascript

前端 未结 5 1737
小鲜肉
小鲜肉 2021-02-14 04:21

I\'m trying to run javascript from a windows command line via script

cscript //NoLogo test.js

However, I can\'t find any predefined objects which are av

5条回答
  •  情歌与酒
    2021-02-14 04:48

    You are using the Windows Scripting Host.

    You can say things like:

    WScript.Echo("Hello, World.");
    

    It's all COM-based, so you instantiate ActiveX controls to do anything useful:

    var y = new ActiveXObject("Scripting.Dictionary");
    y.add ("a", "test");
    if (y.Exists("a"))
       WScript.Echo("true");
    

    Or:

    var fso, f1;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    // Get a File object to query.
    f1 = fso.GetFile("c:\\detlog.txt");   
    // Print information.
    Response.Write("File last modified: " + f1.DateLastModified);
    

    See Windows Script Host.

提交回复
热议问题