Windows 程序员的最佳“官方”脚本语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/326775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best "official" scripting language for Windows programmers
提问by Eugene Yokota
Suppose there were several projects mostly maintained by smart interns, who eventually leave after a period of time. Scripts are used here and there in key parts, for example, to back up a database, rename it, zip it, move it over ssh, unzip it, and then to restore it with different settings. You know, the scripting stuff.
假设有几个项目主要由聪明的实习生维护,他们最终在一段时间后离开。脚本在关键部分到处使用,例如,备份数据库、重命名它、压缩它、将它移动到 ssh 上、解压缩它,然后用不同的设置恢复它。你知道,脚本的东西。
The programming languages for the application side is set, but those for scripts have been relaxed. Currently there are probably healthy mix of bash and .bat file, and maybe some Perl.
应用端的编程语言是固定的,但脚本的编程语言已经放宽了。目前可能有 bash 和 .bat 文件的健康组合,也许还有一些 Perl。
1) To avoid language proliferation, and 2) because I don't want to force bash upon future Windows programmers, I'd like to set an "official" scripting language.
1) 为了避免语言扩散,以及 2) 因为我不想对未来的 Windows 程序员强制使用 bash,我想设置一种“官方”脚本语言。
Google picked Python for this, and it's famous for being readable, easy to learn, and having good library; however, I personally don't find it that readable compared to C-like grammar, Pascal, or Ruby.
Google 为此选择了 Python,它以可读性强、易于学习和拥有良好的库而闻名;但是,我个人认为与类 C 语法、Pascal 或 Ruby 相比,它的可读性并不强。
In any case, if you were to be forced to use only one scripting language on a Windows machine (with Cygwin if you want to) for all scripting, what would you like it to be, and why?
在任何情况下,如果您被迫在 Windows 机器上只使用一种脚本语言(如果您愿意,可以使用 Cygwin)来编写所有脚本,您希望它是什么,为什么?
Related religious wars:
相关宗教War:
回答by ahockley
PowerShell - designed from the ground up to be a Windows scripting language, and it can hook into the CLR for advanced functionality.
PowerShell - 从头开始设计为一种 Windows 脚本语言,它可以连接到 CLR 以获得高级功能。
(yes, I realize this doesn't run under cygwin... but why is that a requirement?)
(是的,我意识到这不在 cygwin 下运行......但为什么这是一个要求?)
回答by Bill Karwin
When I've written cross-platform product installers, coding a UNIX shell script for Linux/Mac/Solaris etc. is really easy, but trying to do equivalent tasks in BAT is like working in the dark, underwater, with both hands tied behind your back. I can't state strongly enough that BAT scripts are a blight on humanity.
当我编写跨平台产品安装程序时,为 Linux/Mac/Solaris 等编写 UNIX shell 脚本真的很容易,但尝试在 BAT 中执行等效任务就像在黑暗中、水下工作,双手被绑在背后你的背部。我不能说BAT 脚本是对人类的一种摧残。
So what I've heard about PowerShellmakes me happy. It's a life-saver for Windows developers. The only trouble is that I believe it's still a separate install, it isn't available by default (I've read that it'll be on Windows Server 2008 and Windows 7).
所以我听说PowerShell让我很高兴。它是 Windows 开发人员的救星。唯一的问题是我认为它仍然是一个单独的安装,默认情况下不可用(我已经读过它将在 Windows Server 2008 和 Windows 7 上)。
Oh well, it only took Microsoft 20 years to replace BAT scripts with something as capable as UNIX shell, so I guess I shouldn't be too ungrateful! >:-P
哦,好吧,微软只用了 20 年的时间就用像 UNIX shell 这样强大的东西替换了 BAT 脚本,所以我想我不应该太忘恩负义!>:-P
Get the installer for PowerShell here:
在此处获取 PowerShell 安装程序:
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
回答by Vilx-
I'll try to provide an alternative - JavaScript and VBScript work fine too even on Windows versions long gone, and they don't need a seperate installation like PowerShell. ;) Of course, PowerShell has more power:P
我将尝试提供一种替代方案 - JavaScript 和 VBScript 即使在早已消失的 Windows 版本上也能正常工作,而且它们不需要像 PowerShell 那样单独安装。;) 当然,PowerShell 更强大:P
回答by Brian C. Lane
I'd urge you to give Python a chance. It looks a little odd to 'C' programmers at first, but its easy to pick up and more importantly easy to remember. You are going to have interns of various skill levels using and modifying the code so you want something that can draw from a wide user base. And if you are going to go to the trouble of installing something new why choose powershell which is going to be a dead end for anyone using it.
我劝你给 Python 一个机会。一开始对'C' 程序员来说看起来有点奇怪,但它很容易上手,更重要的是容易记住。您将有各种技能水平的实习生使用和修改代码,因此您需要可以从广泛的用户群中汲取的东西。如果你要安装一些新的东西,为什么选择 powershell,这对任何使用它的人来说都是死胡同。
回答by jcpennypincher
The best scripting language I have come across for interface and control type applications in Windows is AutoHotKey. Anyone developing on windows should learn about this language... It can save you an enormous amount of time just automating retarded windows tasks...
对于 Windows 中的界面和控件类型应用程序,我遇到的最好的脚本语言是 AutoHotKey。任何在 Windows 上开发的人都应该学习这种语言......它可以为你节省大量时间,只需自动化延迟的 Windows 任务......
One of the most useful tools I have come across for Windows is Texter
我在 Windows 上遇到的最有用的工具之一是Texter
This utility is written in AutoHotKey and saves me from having to type anything more than a few times... An indispensable tool for a coder or anyone filling in forms or tickets...!
这个实用程序是用 AutoHotKey 编写的,让我不必多次输入任何东西......对于编码人员或任何填写表格或票证的人来说都是必不可少的工具......!
回答by dkretz
Powershell. It's got the breadth and the depth, and is fully supported (now and in the future.) Unlike Cygwin, for instance.
电源外壳。它具有广度和深度,并且得到全面支持(现在和将来)。例如,与 Cygwin 不同。
回答by aikeru
For your particular description, PowerShell sounds like a good way to go ... but I would make a strong case for JScript under WSH (or JavaScript under Rhino/etc.). Sounds like you like CYGWIN, but Powershell does not currently have support for other platforms (too much native stuff I think -- that's a separate discussion IMO, but Google should answer it).
对于您的特定描述,PowerShell 听起来是一个不错的方法……但我会为 WSH 下的 JScript(或 Rhino/etc. 下的 JavaScript)提供强有力的支持。听起来你喜欢 CYGWIN,但 Powershell 目前不支持其他平台(我认为太多原生的东西 - 这是 IMO 的单独讨论,但谷歌应该回答它)。
I pretty much make the case here: http://mikesharp.wordpress.com/2011/04/03/jquery-for-administrators/
我几乎在这里说明:http: //mikesharp.wordpress.com/2011/04/03/jquery-for-administrators/
Some highlights:
一些亮点:
- JavaScript is installed by default on every Windows OS after '95
- JScript scripts work "out of the box" with Active Directory
- ECMAScript is an open standard (which JScript is an implementation of)
- Through ActiveX/COM JScript can do most of what Powershell can do and under Rhino it has the power of Java
- Can be used to create HTA applications (and later, metro apps with WinRT/HTML5)
- '95 之后的每个 Windows 操作系统都默认安装 JavaScript
- JScript 脚本与 Active Directory 一起“开箱即用”
- ECMAScript 是一个开放标准(JScript 是它的一个实现)
- 通过 ActiveX/COM JScript 可以做 Powershell 可以做的大部分事情,在 Rhino 下它拥有 Java 的力量
- 可用于创建 HTA 应用程序(以及更高版本的带有 WinRT/HTML5 的 Metro 应用程序)
JScript doesn't have direct access to the .NET framework -- although there are a few 3rd party JavaScript engines in pure .NET that interpret it and can share objects with it like Jurassic and IronJS. Also wrappers like JavaScriptDotNet (around Chrome/V8). Powershell will likely be faster than JScript under WSH, but the same might not be said of other 3rd party interpreters.
JScript 不能直接访问 .NET 框架——尽管在纯 .NET 中有一些 3rd 方 JavaScript 引擎可以解释它并可以与它共享对象,如 Jurassic 和 IronJS。还有像 JavaScriptDotNet 这样的包装器(围绕 Chrome/V8)。在 WSH 下,Powershell 可能比 JScript 更快,但其他 3rd 方解释器可能不会这样说。
Just please don't go with VBScript (lacking try/catch, no real OOP, proprietary, deprecated, etc.).
只是请不要使用 VBScript(缺少 try/catch,没有真正的 OOP,专有的,已弃用等)。
回答by mbirth
If you are like me and want to display nifty progress bars or splash screens while your script is doing it's magic (instead of a black/gray command prompt window), use AutoHotkey. Showing a progress bar is a PITA with JScript/VBScript (WSH) and/or PowerShell from what I've found. In AHK it's as simple as:
如果你像我一样,想要在你的脚本执行它的魔法时显示漂亮的进度条或闪屏(而不是黑色/灰色命令提示符窗口),请使用 AutoHotkey。显示进度条是我发现的带有 JScript/VBScript (WSH) 和/或 PowerShell 的 PITA。在 AHK 中,它很简单:
Progress, b2 m, ACME App, Doing some magic...
Also you can interact with almost any control in any window and automate apps which are not meant to be automated.
此外,您可以与任何窗口中的几乎任何控件进行交互,并自动化不打算自动化的应用程序。