最近我经常使用 jscript.net(以及 WSH 附带的“旧”jscript)。
但永远不要将它与 Visual Studio 一起使用(您可能已经找到了这个)。但只需使用简单的记事本++。
这就是让 jscript 对我如此出色的原因:
- 它在每个 Windows 系统上都可用(即使是最古老的 XP 机器也有一些 .net 框架),因为每个 .net 框架都带有 jscript 编译器。
- 由于 jscript 指令,它非常适合“内置”批处理文件(示例如下)
- 有很多 javascript 代码几乎可以直接在 jscript.net 中使用。毕竟javascript是世界上最流行的编程语言。
- 它背后有 .net 的力量
还有我不喜欢的:
- 看起来它有点被微软抛弃了。
- 即使在 MSDN 上,代码片段/示例也很少。尽管在 90% 的情况下,将 C# 代码重写为 Jscript 很容易。
- jscript.net 中缺少一些很酷的功能,但在其他两种本机 .net 语言(vb 和 cs)中可用 - dll import , generics ..
以下是我在记事本中使用 jscript.net 的方式:
@if (@X)==(@Y) @end /****** silent jscript comment ******
@echo off
::::::::::::::::::::::::::::::::::::
::: compile the script ::::
::::::::::::::::::::::::::::::::::::
setlocal
:: remove the rem bellow when you fell your code is ready to use
rem if exist "%~n0.exe" goto :skip_compilation
:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
if exist "%%v\jsc.exe" (
rem :: the javascript.net compiler
set "jsc=%%~dpsnfxv\jsc.exe"
goto :break_loop
)
)
echo jsc.exe not found && exit /b 0
:break_loop
call %jsc% /nologo /out:"%~n0.exe" "%~f0"
::::::::::::::::::::::::::::::::::::
::: end of compilation ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation
::
::::::::::
"%~n0.exe" %*
::::::::
::
endlocal
exit /b 0
****** end of jscript comment ******/
import System;
Console.WriteLine( "Boo" );
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
您可以将其保存为.bat
文件并运行它。它会自行编译并启动。总的来说,您不必太担心注释中的代码,您可以将其用作模式。