What is the easiest language/program to use to write a script to automate a task. Something that will work on all operating systems preferred but not required.

Played around with bash, python, MS batch files and others. Wondering if there is something better.

link|improve this question
It's the one I haven't written yet. Or haven't finished writing, depending on how you look at it. – Ignacio Vazquez-Abrams Sep 9 '10 at 14:38
+1 - Good question! I wont put this as an answer cause I can't address all the languages mentioned, but I have had great luck with VBScript in windows. Powershell is similar (also Windows). I think the EASIEST is probably Batch files, but you are limited in functionality somewhat. – JNK Sep 9 '10 at 14:39
3  
You listed all of my suggestions in your question... Bash and MS Batch have the advantage of working without needing to install anything extra in their respective operating systems and also being pretty straight forward if you've spent time on the command line in either as well and python is a great programing language that has support in Windows, Linux, and Mac. Is there a more specific reason why you are still looking for something "better"? What reason don't the named ones work for you? – Dan Sep 9 '10 at 14:41
Java being platform independent . I think Java could be your answer – subanki Sep 9 '10 at 14:42
1  
@subanki - Java is really not the most stable language, and is also not well suited to task automation. – JNK Sep 9 '10 at 14:43
show 4 more comments
feedback

5 Answers

up vote 4 down vote accepted

This is obviously partly a matter of opinion. Your requirements as I understand them are:

  • easy to use (and perhaps easy to learn?)
  • good at system automation (manipulating files, launching applications and influencing their behavior, a little text processing, a little concurrency, some networking, some user interaction, ...)
  • preference for platform-independence

Given these requirements, here are what I see as the main contenders:

  • Unix shells (with several variants: the universally supported POSIX sh, or one of its two common supersets bash and ksh, or the common subset of bash and ksh, or zsh). These are the tools of choice for simple automation in the unix world. They have a command line (they are the command line). They are available on Windows, but they are not so well integrated there. They carry 40 years of historical baggage and are quirky at times.

  • Powershell is the scripting language pushed by Microsoft for Windows automation. It has very good Windows integration, but few libraries to interact with applications. It doesn't exist outside Windows. (Forget about cmd a.k.a. batch files for anything nontrivial.)

  • There are several advanced scripting languages that have good implementations on pretty much all desktop/server platforms: Perl, Php, Python, Ruby. Perl is the traditional choice on unix but it's losing market share to Python. Php is used a lot for web scripting and rarely for anything else (and the only reason it's good at web scripting is a ton of existing libraries). Both Perl and Python have a lot of libraries for system scripting. I don't know much about Ruby, but I think it has fewer libraries than Perl or Python (simply because it has a less large user base). Python is definitely easier to learn than Perl.

  • There are several other languages that are good at scripting a particular task but not so good otherwise, such as AppleScript (Apple's scripting language of choice, unheard of outside the Mac world), AutoHotKey (a Windows keyboard macro tool with a horrible scripting language), tcl (an almost-forgotten unix scripting language that Expect and Tk use and pretty much noone else), Lisp/Scheme (several programs are natively scriptable in some dialect, but they tend to use incompatible dialects), ...

  • Of course, there are millions of programming languages out there, but I've mentioned the ones that I consider particularly adapted for system automation.

Based on the above analysis, my conclusion is Python.

link|improve this answer
1  
Most exhaustive description I have seen so far, very well analyzed. Gonna have to go with Python as easiest and most universal at the moment. Obligatory xkcd reference xkcd.com/353 – radix07 Sep 9 '10 at 21:22
feedback

If you want to run on any OS, you've named several already:

  • bash (Linux, Mac OS X, Windows via Cygwin)
  • sh (other Unixes)
  • python (any platform that has an interpreter available)
  • php (see python comment)
  • perl (see php comment)

Of course, you need to have the interpreters / run time environments available to run them.

What are you looking to automate, and why does it need to be the same on every platform?

link|improve this answer
feedback

AutoIt is an awesome scripting language that you might like. The only problem is that it runs only on Windows (so I am not expecting this to be chosen as the correct answer). I still mention it, however, because you can do anything from simple tasks (e.g. simulating keystrokes) to creating complex programs (including a GUI!). From the website:

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying "runtimes" required!

You can view more information about AutoIt, and download it from here.

link|improve this answer
Looks pretty interesting, never heard of it before. – radix07 Sep 9 '10 at 15:37
Yeah, it is incredibly useful. It even has COM support so you can even use the MS Office Interop if you wish! – Breakthrough Sep 9 '10 at 15:43
sounds similar to Apple's AppleScript – warren Sep 9 '10 at 18:26
feedback

As often "best" depends on what you want to achieve. Here is my personal toolkit:

  1. OS independent: python (any platform that has an interpreter available, google favorite language ;)

  2. Windows: Batch, VBS (the successor of BAT) or Powershell (the successor of VBS)

  3. Macro Programs: Autoit/Autohotkey

  4. Browser Automation: iMacros for IE/Firefox/Chrome

link|improve this answer
feedback

Warren is correct, but given BASH and SH' limitations, I'd say these are more independent in terms of being cross-platform ready:

  1. perl
  2. python
  3. php
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.