How to create .exe or .dll files using JScript_javascript tips
WBOY
Release: 2016-05-16 18:04:56
Original
2082 people have browsed it
What is JScript? JScript is an active scripting language developed by Microsoft and implemented based on the ECMAScript specification. JavaScript in Internet Explorer actually refers to JScript. JScript is supported by Windows Script Host (WSH) (JavaScript shell scripting in WSH: C:> cscript jslint.js). The latest version of JScript (JScript.NET) is based on ECMAScript 4.0 and can be compiled in the .Net environment. .NET Framwork includes a JScript compiler: JScriptCompiler (C:WINDOWSMicrosoft.NETFrameworkv2.0.50727jsc.exe), which can compile JScript files into an .exe or .dll file. For ease of use, we can add the path of JScriptCompiler to the environment variable (environment variable –> system variable –> Path). Directly call the command "jsc" in the CMD program running window to see the compiler-related help options.
First create a JS file (C:testhelloWorld.js) with the following content:
var date = new Date(); print('Hello World! nToday is ' date );
Then we compile:
C:test>jsc helloWorld.jsMicrosoft (R) JScript Compiler version 8.00.50727for Microsoft (R) .NET Framework version 2.0.50727Copyright (C) Microsoft Corporation 1996-2005. All rights reserved. You will be surprised to find that there is an extra helloWorld.exe file in the C:test directory. It is very simple, haha
Finally we can directly execute the helloWorld.exe file:
C :test>helloWorldHello World! Today is Fri Jun 3 23:13:20 UTC 8 2011 Done! !
package LibHW { class HelloWorld { function run() { var date = new Date(); return 'Hello World! nToday is ' date; } } }
Compilation statement:
C:test>jsc /t:library LibHW.js For the generated LibHW.dll file, we can create a new .exe file (consumer.js –> ; consumer.exe) is called by importing a module (similar to Python).
First create the consumer.js file:
import LibHW;var hw = new LibHW.HelloWorld();print(hw.run()); Then compile the consumer.js file , execute consumer.exe:
C:test>jsc consumer.jsMicrosoft (R) JScript Compiler version 8.00.50727for Microsoft (R) .NET Framework version 2.0.50727Copyright (C) Microsoft Corporation 1996-2005. All rights reserved. C:test>consumerHello World! Today is Sat Jun 4 00:42:35 UTC 8 2011 Of course you can also create a windows application. The consumer.js file in the above example is modified as follows:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn