How does this Windows batch file run embedded javascript?

后端 未结 1 1802
梦谈多话
梦谈多话 2020-12-18 07:32

How does Windows know that this is JSCRIPT?

@set @junk=1 /*
@echo off
cscript //nologo //E:jscript %0 %*
goto :eof
*/
x = WScript.Arguments
Yr = x(0) ; Mo =          


        
相关标签:
1条回答
  • 2020-12-18 08:01

    It is quite simple really. The first line is valid batch file language for setting a shell variable and everything after the last space is ignored. It is also valid JSCRIPT for setting compile time variables, and the last two chars begin a Javascript comment which causes the rest of the batch file language lines to be ignored.

    The cscript line causes the same file %0 to be executed by JSCRIPT with the same arguments %*. Then the batch goto statement uses :eof which is a builtin label that represents the end of file.

    If you are a beginner, and you spend your time learning how to apply JSCRIPT to the problems of Windows shell scripting, you can reapply your Javascript knowledge in the browser with web applications, with Windows HTML apps (.HTA), and even in shell scripting on Unix platforms that have Rhino or node.js installed.

    0 讨论(0)
提交回复
热议问题