Rob Rob is a multi-language developer. In his spare time, he enjoys riding his motorcycle and playing guitar in his band.

Do you need to process or display PDF files?

Find out why you should be using IDRSolutions software

Python – a Multiplatform Alternative to Bash/Batch Scripts?

2 min read

Here at IDRSolutions, we have multiple scripts for running our different tests, which automate all the tedious setup and whatnot. This lets us run most tests in the background, separate from the IDE (Which then allows for some neat multitasking). While we do have a server periodically running the tests for us, we need to be able to run these locally on demand to assist with finding and fixing bugs, and to make sure our last set of commits won’t set the build server on fire.

Because some of us develop on Windows and others on Mac (Apparently there’s a Linux box or 2 lying around as well), we have 2 scripts for each set of tests: a Batch script for Windows, and a Bash script for Linux and Mac nerds. The issue here is that if we make a change to 1 script, we have to mirror the change in the other as well. Maintaining both scripts is feasible, but can be a pain and become time consuming, especially with the longer ones. What we need is a set of scripts that can run on any OS – enter Python.

So how does Python fit in?

First and foremost: Python is multiplatform. Regardless of OS, we need only 1 script. Fantastic.

Of course, apart from ticking the one and only box that required ticking, I found other benefits in switching to Python:

  • Mac and (most) Linux distributions come with Python pre-installed, and setting it up on Windows was as simple as installing a new program gets with the provided .exe
  • The code is more readable (In the sense that it reads more like plain English)
  • It’s also a fair bit reusable
  • The scripts are easily extended
  • It shortens/simplifies some of the longer scripts.

Python won’t replace everything – like Bash/Batch it’s being used as glue between programs. For example, we’ll still use Ant to build and JUnit to test, just now we’ll have Python managing it all for us instead of Bash/Batch.

Although Bash/Batch scripts are very powerful tools when it comes to smaller tasks, some languages are better suited to longer, more complex programs – every language has its pros and cons depending on what you want to do. Disclaimer: The image is an exaggeration.
Although Bash/Batch scripts are very powerful tools when it comes to smaller tasks, some languages are better suited to longer, more complex programs – every language has its pros and cons depending on what you want to do. Disclaimer: The image is an exaggeration.

But doesn’t Windows 10 have Bash support now?

I was initially excited at the thought of a quick and easy solution, and decided to play around with Bash on Ubuntu on Windows.

However.

I discovered that Bash isn’t actually fully integrated into Windows the way the command line is – you can’t launch any Windows programs, or run any Windows commands from within the Bash shell or a script. Although you can access the same files, Bash on Ubuntu on Windows is separate i.e. any programs you install in the Bash shell cannot be used/accessed/interacted with outside of the shell, and vice-versa. It didn’t help that setting up Bash on Windows was rather awkward (compared to installing Python, for example) having to go through multiple menus and hidden settings to enable the Windows Subsystem for Linux beta. The final nail in the coffin was the requirement of Windows 10 (with the Anniversary Update), which not every Windows machine in the office uses.

Unfortunately this meant that Bash was out of the question.

So why did we pick Python? What was wrong with Perl or Ruby? Couldn’t we have just cut out having to spend time learning another language and just use Java?

Well, that’s a tale for another time.

Have you had any experience using Python/Perl/Ruby/etc. to replace Bash/Batch scripts? Let us know in the comments below.



Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
Rob Rob is a multi-language developer. In his spare time, he enjoys riding his motorcycle and playing guitar in his band.

Should you travel by plane or train?

Why travel to Switzerland by train This year, my daughter set me the challenge to take the train rather than fly when I next...
Mark Stephens
1 min read

2 Replies to “Python – a Multiplatform Alternative to Bash/Batch Scripts?”

  1. Python is an interpreted, interactive , object oriented high level programming language similar to PERL…
    The blog describes the multi platform alternative bash batch scripts…Thanks for sharing this informatives..

Comments are closed.