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

- 8,318
- 10
- 45
- 58
9 Answers
I'm a huge fan of 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.
GUI support through wxLua and other bindings
Some support for hiding OS differences in common tasks, e.g., the Lua File System add-on
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.
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.
Performance beats tcl, perl, python, ruby
For even faster performance on x86 hardware, there is 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).
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.

- 198,648
- 61
- 360
- 533
You could try 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.

- 12,666
- 26
- 78
- 113

- 3,400
- 3
- 30
- 34
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.
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.

- 10,017
- 5
- 38
- 51
-
1Thanks. About the alleged ,,contradictory-ness'' : Generally cross-platform but able to integrate (call into) os-specifics, well. This not that rare. – KarolDepka Apr 14 '10 at 12:48
-
I got the feeling you're leaning to something better than ruby + shell commands combination you mentioned: that's what I meant. I just said that it's not likely you'll find something better than that. – Tomislav Nakic-Alfirevic Apr 14 '10 at 13:04
-
1Groovy is good, but the slow startup of the jvm makes java a non-starter for short scripts IMO. – Bryan Oakley Apr 14 '10 at 13:46
-
Agreed. If it's intended to be invoked multiple times from something else, it's next to useless. It's just a matter of the use cases one is interested in. – Tomislav Nakic-Alfirevic Apr 14 '10 at 14:05
You could write your scripts in 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;
for the Windows-specific functions, you can use Twapi (Win32 API bindings).
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;
- 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.

- 3,663
- 1
- 24
- 25
-
2Tcl also wins because 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. Plus, 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. And, of course, for GUI programming you get native widgets. – Bryan Oakley Apr 14 '10 at 13:44
Like e.g. Ruby driving some Windows-specific stuff
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.

- 1
- 1

- 30,834
- 6
- 70
- 106
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.
For UNIX systems you can use this:
#!/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!

- 583
- 3
- 8
I would use C# with Mono.

- 5,519
- 3
- 29
- 51
-
9That strikes me as an odd choice for scripting. In bash, e.g., you show the contents of a file with `cat file.txt`; in groovy with `println new File("file.txt").text`: how much code (+ compilation) would you have to do with C#? C# may be a nice general purpose OO language, but one thing it does not do well is support scripting. – Tomislav Nakic-Alfirevic Apr 14 '10 at 12:24
-
5Just for reference (without implying that c# is good for scripting) in C# you would write: File.ReadAllText("file.txt") in a repl environment (which is included in mono: http://www.mono-project.com/CsharpRepl ) – Cohen Jul 15 '13 at 12:06
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.

- 753
- 2
- 6
- 24
-
2I don't recommend this. I had the pleasure to work with Ant before and even when it works, it's such a round trip and odd type of programming, due to its declarative nature. It's no similar substitution to bash or batch programming. – Martin Braun Dec 18 '21 at 18:10