I'm looking for cross-platform scripting (language) for windows, Linux, MacOS X. I'm tired of .bat / bash .
I would like to do things like for example ,,lock workstation'' at automatic login (I had this in X-Window but the solution was pretty ugly; now, I would like that on MS Windows and not that ugly :-) ).
Generally: automate tasks.
Or would I be better off with Windows Scripting Host?
PowerShell also comes to mind, but that's seems to Windows-only for my taste. Can languages like Python, Ruby, (Java?) interact (elegantly? sensibly?) with WSH?
Also things like DBUS, DCOM, etc come to mind as part of the picture.
Currently I use a mixture of Java, .bat, bash, Ruby, Scala; some VBA for Excel. Which sometimes gets pretty ugly.
I would like a cross-platform general solution with/using ,,native'' parts close to OS-specifics. Like e.g. Ruby driving some Windows-specific stuff (just a guess).
What do You use?
TIA
我正在为windows、Linux、MacOS x寻找跨平台脚本(语言)。我已经厌倦了。bat / bash。我想做一些事情,例如,在自动登录时锁定工作站(我在X-Window中有这个但是解决方案很糟糕;现在,我想要在微软视窗上,而不是那丑陋的:)。一般:自动化任务。或者使用Windows脚本主机更好?PowerShell也出现在我的脑海中,但这似乎只是为了满足我的口味。像Python、Ruby (Java?)这样的语言可以交互吗?WSH理智?)?还有像DBUS, DCOM等等,这些都是图片的一部分。目前我混合使用Java、.bat、bash、Ruby和Scala;一些Excel VBA。有时候会变得很丑。我想要一个跨平台的通用解决方案,包含/使用、本机的部分,这些部分与操作系统相关。比如Ruby驾驶一些特定于windows的东西(只是猜测)。你使用什么?蒂雅
9 个解决方案
#1
3
I think you're juggling on the edge of contradictory: you would like platform-independent (commendable) but also "close to OS specifics".
我认为你在矛盾的边缘徘徊:你希望平*立(值得称赞),但也希望“接近操作系统的细节”。
If, however, you put a bit more emphasis on platform independence, I've been entertaining the idea of using groovy (a more java-friendly relative of ruby) for general purpose scripting. When you need it, you get OS-specific behaviour by invoking OS shell commands.
但是,如果您更强调平*立性,我一直在考虑将groovy (ruby的一个更友好的java亲戚)用于通用目的脚本编写。当您需要它时,您可以通过调用OS shell命令获得特定于操作系统的行为。
My motivation is a bit different: I find groovy code to be more robust than that of bash, although I too will need a good multi-platform scripting tool for a project I'm developing.
我的动机有点不同:我发现groovy代码比bash更健壮,尽管我也需要一个好的多平台脚本工具来开发我正在开发的项目。
#2
15
I'm a huge fan of Lua:
我是Lua的超级粉丝:
-
Syntax is vaguely Pascal-like and works well in scripts.
语法类似于护照,在脚本中很好用。
-
Superb power-to-weight ratio. Superb engineering. Very good design.
出色的功率重量比。一流的工程。非常好的设计。
-
Extremely portable to any platform with an ANSI C compiler.
具有ANSI C编译器的任何平台都具有极大的可移植性。
-
GUI support through wxLua and other bindings
通过wxLua和其他绑定支持GUI
-
Some support for hiding OS differences in common tasks, e.g., the Lua File System add-on
一些支持隐藏常见任务中的OS差异,例如Lua文件系统附加组件
-
The core system and libraries are simple enough that you can understand all of what you're using, but still have excellent leverage compared to bash/bat. Expressive power is comparable to Python or Ruby.
核心系统和库非常简单,您可以理解所使用的所有内容,但是与bash/bat相比,它们仍然具有很好的优势。表达能力可与Python或Ruby相比。
-
You're not overwhelmed with libraries and frameworks, which can be a plus or a minus.
您不会被库和框架所淹没,这些库和框架可以是正负号。
-
There is an excellent book: Roberto Ierusalimschy's Programming in Lua; you can get the previous edition free online.
有一本很棒的书:Roberto Ierusalimschy的Lua编程;你可以在网上免费获得先前版本。
-
Performance beats tcl, perl, python, ruby
性能胜过tcl、perl、python、ruby
-
For even faster performance on x86 hardware, there is LuaJIT.
对于x86硬件上更快的性能,还有LuaJIT。
-
Finally, and this is the ace in the hole: if you run into any kind of platform-specific problem, it is easy to write platform-specific C code and load it into a Lua script dynamically. Lua was designed with this task in mind and does it extremely well. You can also easily dip into C for performance (e.g., compute MD5 checksum).
最后,这是王牌:如果遇到任何特定于平台的问题,很容易编写特定于平台的C代码并将其动态加载到Lua脚本中。Lua在设计时考虑了这个任务,并且做得非常好。您还可以轻松地使用C来提高性能(例如,计算MD5校验和)。
Over the last 3 to 5 years, I have been gradually migrating scripts from bash/ksh/awk/sed/grep/perl into Lua. I have been very happy with the results.
在过去的3到5年中,我逐渐将脚本从bash/ksh/awk/sed/grep/perl迁移到Lua。我对结果非常满意。
#3
6
Perl and Python are both available on almost every platform
几乎在每个平台上都可以使用Perl和Python
#4
5
You could try Batsh
你可以试试Batsh
Batsh is a simple programming language that compiles to Bash and Windows Batch. It enables you to write your script once runs on all platforms without any additional dependency.
Batsh是一种简单的编程语言,可编译为Bash和Windows批处理。它使您能够在所有平台上运行时编写脚本,而不需要任何附加依赖。
#5
4
You could write your scripts in Tcl.
您可以用Tcl编写脚本。
-
the syntax is simple and closer to what you'd expect from a script;
语法简单,更接近于您对脚本的期望;
-
it is cross-platform, and will run on all major platforms;
它是跨平台的,将在所有主要平台上运行;
-
you can easily create simple GUIs for your scripts in Tk, which will also work everywhere and use native controls;
您可以轻松地为Tk中的脚本创建简单的gui,它也可以在任何地方工作并使用本机控件;
-
for the Windows-specific functions, you can use Twapi (Win32 API bindings).
对于特定于windows的函数,可以使用Twapi (Win32 API绑定)。
-
you can install a Tclkit, which is a single file that is the whole Tcl distribution. There's no lengthy install process or hidden files or mysterious directories;
您可以安装Tclkit,它是整个Tcl发行版的一个文件。没有冗长的安装过程或隐藏文件或神秘的目录;
- you can easily put a linux, windows and mac runtime on a single flash drive so you always have an interpreter handy even if there's not one installed locally.
- 你可以很容易地将linux、windows和mac运行时放在一个闪存驱动器上,这样即使没有本地安装的解释器,你也可以随时使用它。
#6
2
Like e.g. Ruby driving some Windows-specific stuff
比如Ruby在驱动一些特定于windows的东西
It certainly can and on the Ruby on Windows blog you can find lots of examples also there's a chapter in the Pickaxe book and in the humble one.
它当然可以,在Ruby on Windows博客上,你可以找到很多例子,在《鹤嘴锄》一书中有一章,在拙作中也有。
#7
0
I would use C# with Mono.
我会使用c#和Mono。
#8
0
there is possibility for UNIX and UNIX like platforms in shell, but I don`t think that this what you are asking for is possible in any scripting language because of windows.
有可能在shell中使用UNIX和UNIX之类的平台,但我认为,由于windows的原因,您所要求的在任何脚本语言中都不可能实现。
For UNIX systems you can use this:
对于UNIX系统,您可以使用以下命令:
#!/bin/sh
TYPE=`uname`;
echo 'this is ' ${TYPE};
if [ ${TYPE} = HP-UX ]
then bdf /var;
elif [ ${TYPE} = Linux ]
then df -h /var;
elif [ ${TYPE} = FreeBSD ]
then df -k /var;
else echo "Unsupported OS - ${TYPE}"
fi
I hope it will help you!
我希望它能帮助你!
源
#9
0
Not sure if you still need it, but if so, try ant ( http://ant.apache.org/ ). It's a cross platform "script language". Basically, a ant file is a xml file interpreted by a JVM programm.
不确定是否仍然需要它,但如果需要,请尝试ant (http://ant.apache.org/)。它是一种跨平台的“脚本语言”。基本上,ant文件是由JVM程序解释的xml文件。
#1
3
I think you're juggling on the edge of contradictory: you would like platform-independent (commendable) but also "close to OS specifics".
我认为你在矛盾的边缘徘徊:你希望平*立(值得称赞),但也希望“接近操作系统的细节”。
If, however, you put a bit more emphasis on platform independence, I've been entertaining the idea of using groovy (a more java-friendly relative of ruby) for general purpose scripting. When you need it, you get OS-specific behaviour by invoking OS shell commands.
但是,如果您更强调平*立性,我一直在考虑将groovy (ruby的一个更友好的java亲戚)用于通用目的脚本编写。当您需要它时,您可以通过调用OS shell命令获得特定于操作系统的行为。
My motivation is a bit different: I find groovy code to be more robust than that of bash, although I too will need a good multi-platform scripting tool for a project I'm developing.
我的动机有点不同:我发现groovy代码比bash更健壮,尽管我也需要一个好的多平台脚本工具来开发我正在开发的项目。
#2
15
I'm a huge fan of Lua:
我是Lua的超级粉丝:
-
Syntax is vaguely Pascal-like and works well in scripts.
语法类似于护照,在脚本中很好用。
-
Superb power-to-weight ratio. Superb engineering. Very good design.
出色的功率重量比。一流的工程。非常好的设计。
-
Extremely portable to any platform with an ANSI C compiler.
具有ANSI C编译器的任何平台都具有极大的可移植性。
-
GUI support through wxLua and other bindings
通过wxLua和其他绑定支持GUI
-
Some support for hiding OS differences in common tasks, e.g., the Lua File System add-on
一些支持隐藏常见任务中的OS差异,例如Lua文件系统附加组件
-
The core system and libraries are simple enough that you can understand all of what you're using, but still have excellent leverage compared to bash/bat. Expressive power is comparable to Python or Ruby.
核心系统和库非常简单,您可以理解所使用的所有内容,但是与bash/bat相比,它们仍然具有很好的优势。表达能力可与Python或Ruby相比。
-
You're not overwhelmed with libraries and frameworks, which can be a plus or a minus.
您不会被库和框架所淹没,这些库和框架可以是正负号。
-
There is an excellent book: Roberto Ierusalimschy's Programming in Lua; you can get the previous edition free online.
有一本很棒的书:Roberto Ierusalimschy的Lua编程;你可以在网上免费获得先前版本。
-
Performance beats tcl, perl, python, ruby
性能胜过tcl、perl、python、ruby
-
For even faster performance on x86 hardware, there is LuaJIT.
对于x86硬件上更快的性能,还有LuaJIT。
-
Finally, and this is the ace in the hole: if you run into any kind of platform-specific problem, it is easy to write platform-specific C code and load it into a Lua script dynamically. Lua was designed with this task in mind and does it extremely well. You can also easily dip into C for performance (e.g., compute MD5 checksum).
最后,这是王牌:如果遇到任何特定于平台的问题,很容易编写特定于平台的C代码并将其动态加载到Lua脚本中。Lua在设计时考虑了这个任务,并且做得非常好。您还可以轻松地使用C来提高性能(例如,计算MD5校验和)。
Over the last 3 to 5 years, I have been gradually migrating scripts from bash/ksh/awk/sed/grep/perl into Lua. I have been very happy with the results.
在过去的3到5年中,我逐渐将脚本从bash/ksh/awk/sed/grep/perl迁移到Lua。我对结果非常满意。
#3
6
Perl and Python are both available on almost every platform
几乎在每个平台上都可以使用Perl和Python
#4
5
You could try Batsh
你可以试试Batsh
Batsh is a simple programming language that compiles to Bash and Windows Batch. It enables you to write your script once runs on all platforms without any additional dependency.
Batsh是一种简单的编程语言,可编译为Bash和Windows批处理。它使您能够在所有平台上运行时编写脚本,而不需要任何附加依赖。
#5
4
You could write your scripts in Tcl.
您可以用Tcl编写脚本。
-
the syntax is simple and closer to what you'd expect from a script;
语法简单,更接近于您对脚本的期望;
-
it is cross-platform, and will run on all major platforms;
它是跨平台的,将在所有主要平台上运行;
-
you can easily create simple GUIs for your scripts in Tk, which will also work everywhere and use native controls;
您可以轻松地为Tk中的脚本创建简单的gui,它也可以在任何地方工作并使用本机控件;
-
for the Windows-specific functions, you can use Twapi (Win32 API bindings).
对于特定于windows的函数,可以使用Twapi (Win32 API绑定)。
-
you can install a Tclkit, which is a single file that is the whole Tcl distribution. There's no lengthy install process or hidden files or mysterious directories;
您可以安装Tclkit,它是整个Tcl发行版的一个文件。没有冗长的安装过程或隐藏文件或神秘的目录;
- you can easily put a linux, windows and mac runtime on a single flash drive so you always have an interpreter handy even if there's not one installed locally.
- 你可以很容易地将linux、windows和mac运行时放在一个闪存驱动器上,这样即使没有本地安装的解释器,你也可以随时使用它。
#6
2
Like e.g. Ruby driving some Windows-specific stuff
比如Ruby在驱动一些特定于windows的东西
It certainly can and on the Ruby on Windows blog you can find lots of examples also there's a chapter in the Pickaxe book and in the humble one.
它当然可以,在Ruby on Windows博客上,你可以找到很多例子,在《鹤嘴锄》一书中有一章,在拙作中也有。
#7
0
I would use C# with Mono.
我会使用c#和Mono。
#8
0
there is possibility for UNIX and UNIX like platforms in shell, but I don`t think that this what you are asking for is possible in any scripting language because of windows.
有可能在shell中使用UNIX和UNIX之类的平台,但我认为,由于windows的原因,您所要求的在任何脚本语言中都不可能实现。
For UNIX systems you can use this:
对于UNIX系统,您可以使用以下命令:
#!/bin/sh
TYPE=`uname`;
echo 'this is ' ${TYPE};
if [ ${TYPE} = HP-UX ]
then bdf /var;
elif [ ${TYPE} = Linux ]
then df -h /var;
elif [ ${TYPE} = FreeBSD ]
then df -k /var;
else echo "Unsupported OS - ${TYPE}"
fi
I hope it will help you!
我希望它能帮助你!
源
#9
0
Not sure if you still need it, but if so, try ant ( http://ant.apache.org/ ). It's a cross platform "script language". Basically, a ant file is a xml file interpreted by a JVM programm.
不确定是否仍然需要它,但如果需要,请尝试ant (http://ant.apache.org/)。它是一种跨平台的“脚本语言”。基本上,ant文件是由JVM程序解释的xml文件。