|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Compile JScript Code from the Command Line
Updated: December 2009
To produce an executable JScript program, you must use the command-line compiler, jsc.exe. There are several ways to start the compiler.
If Visual Studio is installed, you can use the Visual Studio Command Prompt to access the compiler from any directory on your machine. The Visual Studio Command Prompt is in the Visual Studio Tools program folder within the Microsoft Visual Studio program group.
As an alternative, you can start the compiler from a Windows command prompt, which is the typical procedure if Visual Studio is not installed.
To start the compiler from a Windows command prompt, you must run the application from within its directory or type the fully qualified path to the executable at the command prompt. To override this default behavior, you must modify the PATH environment variable, which enables you to run the compiler from any directory by simply typing the compiler name.
To modify the PATH environment variable
Use the Windows search feature to find jsc.exe on your drive. The exact name of the directory where jsc.exe is located depends on the name and location of the Windows directory and the version of the .NET Framework that is installed. If you have more than one version of the .NET Framework installed, you must determine which version to use (typically the latest version).
For example, the compiler might be located at C:\Windows\Microsoft.NET\Framework\v2.0.50727.
To display the System Information dialog box, right-click Computer or My Computer on the desktop, and then click Properties.
If you are using Windows Vista or Windows 7, click Advanced System settings in the resulting Control Panel window.
On the Advanced tab of the System Properties dialog box, click Environment Variables.
Under System variables, select Path from the list and click Edit.
In the Edit System Variable dialog box, move the cursor to the end of the string in the Variable Value box and type a semicolon (;) followed by the full directory name that you found in Step 1.
For example, if the compiler is at the location specified in the example in Step 1, you would type the following:
Click OK to confirm your edits and close the dialog boxes.
Open a new command prompt.
After you change the PATH environment variable, you can run the JScript compiler at the Windows command prompt from any directory on the machine.
The command-line compiler has some built-in help. A help screen is displayed by using the /help or /? command-line option or by using the compiler without any options. For example:
There are two ways to use JScript. You can write programs to be compiled from the command line, or you can write programs to be run in ASP.NET.
To compile using jsc
At the command prompt, type jsc file.js
The command compiles the program named file.js to produce the executable file named file.exe.
To produce a .dll file using jsc
At the command prompt, type jsc /target:library file.js
The command compiles the program named file.js with the /target:library option to produce the library file named file.dll.
To produce an executable with a different name using jsc
At the command prompt, type jsc /out:newname.exe file.js
The command compiles the program named file.js with the /out: option to produce the executable named newname.exe.
To compile with debugging information using jsc
At the command prompt, type jsc /debug file.js
The command compiles the program named file.js with the /debug option to produce the executable named file.exe and a file named file.pdb that contains debugging information.
There are many more command-line options available for the JScript command-line compiler. For more information, see JScript Compiler Options.