shell.windows
JavaScript can run virtually anywhere, including as a windows exe and the windows command line.
JavaScript几乎可以在任何地方运行,包括作为Windows exe和Windows命令行。
Say you have a JavaScript function foo()
假设您有一个JavaScript函数foo()
function foo(input) {
var output = input;
// .. unicorns
return output;
}
In order to make this a windows shell script you add at the and a way to read standard input and then write to the standard output:
为了使它成为Windows Shell脚本,您在和添加了一种读取标准输入然后写入标准输出的方式:
(function () {
var input = WScript.StdIn.ReadAll(),
output = foo(input);
WScript.StdOut.Write(output);
}());
Then you run this script, say foo.js
, like:
然后运行此脚本,说foo.js
,例如:
$ cscript foo.js < input.txt
And it prints the output to the console.
然后将输出打印到控制台。
If you want to read and print the code of foo.js itself you go:
如果您想阅读和打印foo.js本身的代码,请执行以下操作:
$ cscript foo.js < foo.js
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
function foo(input) {
var output = input;
...
You can remove this "Microsoft (R) Windows..." stuff with //NoLogo
parameter:
您可以使用//NoLogo
参数删除此“ Microsoft(R)Windows ...”内容:
$ cscript //NoLogo foo.js < foo.js
function foo(input) {
var output = input;
...
CSSMin.JS(CSSMin.JS)
Alrighty, going back to the title of the post.
好了,回到帖子的标题。
CSSMin.js is a port of YUICompressor's CSS minifier (source, hosted tool). Now adding a few lines at the end makes a windows shell script:
CSSMin.js是YUICompressorCSS缩小器( source ,托管工具)的端口。 现在,在最后添加几行,制作一个Windows Shell脚本:
(function () {
var src = WScript.StdIn.ReadAll();
if (!src) {
// help!
WScript.StdOut.WriteLine("cscript //NoLogo cssmin.js < in.css > out.css");
return;
}
WScript.StdOut.Write(YAHOO.compressor.cssmin(src));
}());
Use it like:
像这样使用它:
$ cscript //NoLogo cssmin.js < in.css > out.css
Don't forget the //NoLogo or you'll end up with "Microsoft..." in your minified files
不要忘记// NoLogo,否则在缩小的文件中将出现“ Microsoft ...”
Random observation: "dude"[0] === "d"
in most JS environments but is undefined
in WSH (Windows Scripting Host). So "dude".substring(0, 1)
随机观察:在大多数JS环境中, "dude"[0] === "d"
,但在WSH(Windows脚本宿主)中undefined
。 因此, "dude".substring(0, 1)
Tell your friends about this post on Facebook and Twitter
在Facebook和Twitter上告诉您的朋友有关此帖子的信息
shell.windows