views:

939

answers:

8

What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools.

The scripts would be used to trigger processes such as wget etc to call web services, or other applications/tools that need to run in a specific order with specific parameters.

We primarily work with the Windows stack, but there is a good chance we will need to support Unix in the future.

Thanks.

+2  A: 

The questions is kind of vague, but Python is much more portable than PowerShell; however, Python isn't that prevalent on Windows. But on the other hand, I don't believe PowerShell scripts will work on a Windows machine that doesn't have PowerShell. Meaning they may not work in the old fashioned cmd shell. I think you'll find more documentation and libraries for Python as well.

Powershell is more like Bash than it is a programming language like Python.

Maybe you could explain what you want to do with your scripts and you'll probably get better answers.

jonescb
Question was edited to be more clear, so my answer may look a little silly.
jonescb
why not edit the answer?
Michael Easter
+1  A: 

One advantage to Python is the availability of third-party libraries and an extensive built-in standard library. You can do a lot of powerful operations quickly and easily with Python on a variety of operating systems and environments. That's one reason we use Python here at the office not only as a scripting language but for all of our database backend applications as well.

We also use it for XML and HTML scraping, using ElementTree and BeautifulSoup, which are very powerful and flexible Python-specific libraries for this sort of work.

Brent Newey
+10  A: 

Python works as a great, all-purpose tool if you're looking to replace CMD and BAT scripts on your Windows boxes, and can also be written to run scripts on your (L)inux boxes, too. It's a great, flexible language and can handle many tasks you throw at it.

That being said, Powershell is an amazingly versatile tool for admining all manner of Windows boxes; it has all the power of .NET, with many more interfaces into MS products such as Exchange and Active Directory, which are a timesaver. Depending on your situation, you may get more use of of PS than other scripting languages just because of the interfaces available to MS products, and I know MS seems to have made a commitment to providing those APIs in a lot of products. Powershell comes installed on Windows 7 and Server 2008 and R2, and is fairly easily installed on old versions of Windows.

To address your edit that your scripts will be used to launch other processes, I think in that case either of the tools fit the bill. I would recommend PS if you plan on adding any admin-ish tasks to the scripts rather than just service calls, but if you stick to what you described, Python is good.

MattGWagner
+1 Well-balanced answer.
micahwittman
+1 Good answer, but I think he needs to specify what operating system(s) he plans to do this on to get a better answer.
Bratch
I can't speak for Powershell but Python was a nicer way to script MS Word (via OLE Automation) than VBA.
J.F. Sebastian
You're right J.F., it's pretty sad how difficult it seems to work with MS Office products from within their own languages... maybe I'm missing something
MattGWagner
A: 

I find it sad no one yet mentioend good ol' Perl.

ldigas
PowerShell is one of its progeny, though.
Steve Gilham
PowerShell is still in its roots, and available normally only under 7 (yes, i know it can be installed on xp). Although Perl isn't native on windows at all, I still find it more practical, since it exists for all windows versions, and many of its usability is portable. Not to mention that probably anything the op wants somebody's already done in it <-- call it cheating :) (not rooting against PS, just laying out the cruel reality).
ldigas
+1  A: 

If you are working with web based scripting, then ActiveState's ActivePython seems to have a lot of support for Windows specific API's that would suit you and it has tons of great portable libraries for doing web based work.

pokstad
+4  A: 

IronPython has access to all of the same .NET assemblies as any other .NET language for writing system dependent scripts on Windows. But the same knowledge of Python can be used to write similar scripts on Linux, Solaris, BSD, or OS/X. If you use the standard C Python on Windows, then you can access any COM objects and it is straightforward to translate VBA examples into Python code. The SPAMBayes Outlook plugin is a good example of how far you can go with that. http://spambayes.sourceforge.net/

Python's best feature is the "batteries included" standard library, and even though this is not distributed with IronPython, much of it will work if you just point IronPython to the installed library folder from CPython. In fact, most pure Python libraries, i.e. no compiled C or C++ modules, will work fine with IronPython. On Windows, you also have the choice of installing Python through Cygwin.com which then allows you to use a lot of modules that are normally considered UNIX-only. This can be of use if you have to maintain cross-platform scripts and you prefer consistency rather than special case coding for each OS.

And if you should need to leverage some Java classes, then Jython allows you to use the same Python language that you know to leverage this. Combine this with a nice message queuing system like RabbitMQ, and you can have Python, Jython and IronPython scripts on multiple machines all cooperating in getting the job done.

There is also a huge selection of 3rd party Python modules out there and you could spend several months trawling through delicious.com before you run out of new discoveries. This means that when you need something not part of standard Python libraries, a bit of Googling often comes up with a solution.

Some useful Python modules for scripting to replace bash, CMD and BAT files are PEXPECT http://www.noah.org/wiki/Pexpect and Python WMI http://timgolden.me.uk/python/wmi/index.html

But, in the end, Python also works just fine for simple straightforward scripts that don't need any special features... yet!

Michael Dillon
Another advantage of IronPython over PowerShell is that for back-version operating systems, so long as you have .net already present, it can be rolled out by just an XCOPY deployment.
Steve Gilham
+1  A: 

We would like to standardize our scripting and are currently using bat and cmd files as the standard.

It sounds like Windows is your predominate environment.

If so, PowerShell would be much better than Python.

  • PowerShell is included with Windows Server 2008. No need to deploy/install Python runtime on every new server that rolls in.
  • The entire Microsoft server related software (Exchange, Systems Center, etc) is transitioning to PowerShell cmdlets for functionality and extensions
  • 3rd party vendors (e.g. SCOM plugins) will also use PowerShell scripts/cmdlets to expose functionality

I have more experience with Python than PowerShell but the writing is on the wall as far as the Microsoft ecosystem is concerned: go with PowerShell. Otherwise, you'll just be going against the grain and constantly interop-ing between Python and everyone else's cmdlets.

Just because you can code import win32com.client in Python does not put it on equal footing with PowerShell in the Windows environment.

JasDev
+1  A: 

If all you do is spawning a lot of system specific programs with no or little programming logic behind then OS specific shell might be a better choice than a full general purpose programming language.

J.F. Sebastian