JavaScript 控制台程序
JavaScript Console Program
我想知道...
我可以使用类似 JavaScript 的脚本为 Windows 创建控制台应用程序吗...
如代码:
window.console.write("Hello, World!");
var useless = window.prompt("Press a key...");
而且我想知道是否可以将这样的代码编译成可以在批处理文件中调用的 EXE
。我知道使用 node.js 的可能解决方案,但这并不是我想要的。
提前致谢!
~CSS
您可以尝试 Stoyan Stefanov 在他的文章 Make your javascript a Windows .exe. He explains how you can use the jsc JScript compiler (which is part of the .NET framework) to create executables. According to the JScript article on Wikipedia 中描述的方法,JScript 与 JavaScript.
非常相似(甚至相同)
Stoyan 文章中的一个简单 Hello.js
示例(稍作修改):
var dateToday = new Date();
var randomNumber = Math.random();
print('Hello, \ntoday is ' + dateToday + '\nand this is random - ' + randomNumber);
可以使用如下命令完成编译(在您的计算机上搜索 .NET 框架的位置):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc.exe Hello.js
输出应如下所示:
Hello,
today is Fri Oct 21 23:54:43 UTC+1 2016
and this is random - 0.5690976188374206
我想知道...
我可以使用类似 JavaScript 的脚本为 Windows 创建控制台应用程序吗...
如代码:
window.console.write("Hello, World!");
var useless = window.prompt("Press a key...");
而且我想知道是否可以将这样的代码编译成可以在批处理文件中调用的 EXE
。我知道使用 node.js 的可能解决方案,但这并不是我想要的。
提前致谢!
~CSS
您可以尝试 Stoyan Stefanov 在他的文章 Make your javascript a Windows .exe. He explains how you can use the jsc JScript compiler (which is part of the .NET framework) to create executables. According to the JScript article on Wikipedia 中描述的方法,JScript 与 JavaScript.
非常相似(甚至相同)Stoyan 文章中的一个简单 Hello.js
示例(稍作修改):
var dateToday = new Date();
var randomNumber = Math.random();
print('Hello, \ntoday is ' + dateToday + '\nand this is random - ' + randomNumber);
可以使用如下命令完成编译(在您的计算机上搜索 .NET 框架的位置):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc.exe Hello.js
输出应如下所示:
Hello,
today is Fri Oct 21 23:54:43 UTC+1 2016
and this is random - 0.5690976188374206