What is JScript?
JScript is an active scripting language developed by Microsoft and is implemented based on the ECMAScript specification. JavaScript in Internet Explorer actually refers to JScript. JScript has been supported by Windows Script Host (WSH) (JavaScript shell scripting in WSH: C:\> cscript). The latest version of JScript () is based on ECMAScript 4.0 and can be compiled in a .Net environment.
The .NET Framwork contains the JScript compiler: JScriptCompiler (C:\WINDOWS\\Framework\v2.0.50727\), which can compile a JScript file into a .exe or .dll file.
For ease of use, we can add the path of JScriptCompiler to the environment variable (Environment variables -> System variables -> Path). By calling the command "jsc" directly in the CMD program run window, you can see the compiler-related help options.
jsc [Options] <source file> [[Options] <source file>…]
JScript compiler options
– Output file -
/out:<file> Specifies the name of the binary output file
/t[arget]:exe Create a console application (default)
/t[arget]:winexe Creates Windows Application
/t[arget]:library Create library assembly
/platform:<platform> Limits the platform on which this code can run; it must be x86, Itanium, x64, or anycpu. Default is anycpu
– Input file -
/autoref[+|-] Automatic reference assembly based on imported namespace and fully qualified names (default case)
In the case on)
/lib:<path> Specifies the additional directory in which to search for reference
/r[eference]:<file list> Reference metadata from the specified assembly file <file list>: <assembly name>[;<assembly name>...]
- resource -
/win32res:<file> Specify Win32 resource file (.res)
/res[ource]:<info> Embed the specified resource <info>: <filename>[,<name>[,public|private]]
/linkres[ource]:<info> Links the specified resource to this assembly <info>: <filename>[,<name>[,public|private]]
– Code Generation -
/debug[+|-] sends debug information
/fast[+|-] Disable language features to make code generation better
/warnaserror[+|-] treats warnings as errors
/w[arn]:<level> Set warning level (0-4)
– Miscellaneous –
@<filename> Read the response file for more options
/? Show Help
/help Show Help
/define]:<symbols> Define conditional compilation symbols
/nologo does not display the compiler copyright logo
/print[+|-] provides the print() function
– Advanced -
/codepage:<id> Open source file with the specified code page ID
/lcid:<id> Use the specified LCID for the message and default code pages
/nostdlib[+|-] does not import standard library() and change the default value of autoref to off
/utf8output[+|-] emits compiler output in UTF-8 character encoding
/versionsafe[+|-] Specify default values for members not marked as "override" or "hide"
Create a .exe file
First create the JS file (C:\test\), with the following content:
var date = new Date(); print('Hello World! \nToday is ' + date );
Then we compile:
C:\test>jsc (R) JScript Compiler version 8.00.50727 for 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 file in the C:\test directory, it's very simple, haha
Finally, we can execute the file directly:
C:\test>helloWorldHello World!Today is Fri Jun 3 23:13:20 UTC+8 2011
The work is done! !
Create a .dll file
Creating .dll files is also very simple:
package LibHW {
class HelloWorld {
function run() {
var date = new Date();
return 'Hello World! \nToday is ' + date;
}
}
}
Compile statement:
C:\test>jsc /t:library
For the generated file, we can call it in the way of importing the module by creating a new .exe file (-> ) (similar to Python).
Create the file first:
import LibHW;var hw = new ();print(());
Then compile the file and execute:
C:\test>jsc (R) JScript Compiler version 8.00.50727 for 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 Windows applications. The file in the above example is modified as follows:
import ; // this has a MessageBox class
import LibHW;
var hw = new ();
(
(),
"Dude!",
,
);
Compile statement:
C:\test>jsc /t:winexe
Double-click the newly generated file, haha, isn’t it a sense of accomplishment!
From the above example, we can see that JScript has unlimited potential, nothing can be done, only unexpected.
Extended reading:
JScript is an active scripting language developed by Microsoft and is implemented based on the ECMAScript specification. JavaScript in Internet Explorer actually refers to JScript. JScript has been supported by Windows Script Host (WSH) (JavaScript shell scripting in WSH: C:\> cscript). The latest version of JScript () is based on ECMAScript 4.0 and can be compiled in a .Net environment.
The .NET Framwork contains the JScript compiler: JScriptCompiler (C:\WINDOWS\\Framework\v2.0.50727\), which can compile a JScript file into a .exe or .dll file.
For ease of use, we can add the path of JScriptCompiler to the environment variable (Environment variables -> System variables -> Path). By calling the command "jsc" directly in the CMD program run window, you can see the compiler-related help options.
Copy the codeThe code is as follows:
jsc [Options] <source file> [[Options] <source file>…]
JScript compiler options
– Output file -
/out:<file> Specifies the name of the binary output file
/t[arget]:exe Create a console application (default)
/t[arget]:winexe Creates Windows Application
/t[arget]:library Create library assembly
/platform:<platform> Limits the platform on which this code can run; it must be x86, Itanium, x64, or anycpu. Default is anycpu
– Input file -
/autoref[+|-] Automatic reference assembly based on imported namespace and fully qualified names (default case)
In the case on)
/lib:<path> Specifies the additional directory in which to search for reference
/r[eference]:<file list> Reference metadata from the specified assembly file <file list>: <assembly name>[;<assembly name>...]
- resource -
/win32res:<file> Specify Win32 resource file (.res)
/res[ource]:<info> Embed the specified resource <info>: <filename>[,<name>[,public|private]]
/linkres[ource]:<info> Links the specified resource to this assembly <info>: <filename>[,<name>[,public|private]]
– Code Generation -
/debug[+|-] sends debug information
/fast[+|-] Disable language features to make code generation better
/warnaserror[+|-] treats warnings as errors
/w[arn]:<level> Set warning level (0-4)
– Miscellaneous –
@<filename> Read the response file for more options
/? Show Help
/help Show Help
/define]:<symbols> Define conditional compilation symbols
/nologo does not display the compiler copyright logo
/print[+|-] provides the print() function
– Advanced -
/codepage:<id> Open source file with the specified code page ID
/lcid:<id> Use the specified LCID for the message and default code pages
/nostdlib[+|-] does not import standard library() and change the default value of autoref to off
/utf8output[+|-] emits compiler output in UTF-8 character encoding
/versionsafe[+|-] Specify default values for members not marked as "override" or "hide"
Create a .exe file
First create the JS file (C:\test\), with the following content:
var date = new Date(); print('Hello World! \nToday is ' + date );
Then we compile:
C:\test>jsc (R) JScript Compiler version 8.00.50727 for 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 file in the C:\test directory, it's very simple, haha
Finally, we can execute the file directly:
C:\test>helloWorldHello World!Today is Fri Jun 3 23:13:20 UTC+8 2011
The work is done! !
Create a .dll file
Creating .dll files is also very simple:
Copy the codeThe code is as follows:
package LibHW {
class HelloWorld {
function run() {
var date = new Date();
return 'Hello World! \nToday is ' + date;
}
}
}
Compile statement:
C:\test>jsc /t:library
For the generated file, we can call it in the way of importing the module by creating a new .exe file (-> ) (similar to Python).
Create the file first:
import LibHW;var hw = new ();print(());
Then compile the file and execute:
C:\test>jsc (R) JScript Compiler version 8.00.50727 for 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 Windows applications. The file in the above example is modified as follows:
Copy the codeThe code is as follows:
import ; // this has a MessageBox class
import LibHW;
var hw = new ();
(
(),
"Dude!",
,
);
Compile statement:
C:\test>jsc /t:winexe
Double-click the newly generated file, haha, isn’t it a sense of accomplishment!
From the above example, we can see that JScript has unlimited potential, nothing can be done, only unexpected.
Extended reading:
- 《Make your javascript a Windows .exe》
- 《JavaScript shell scripting》