How to compile wmic on a modern GNU/Linux system

Deprecation is feared by many coders and software engineers, due to its ability to completely break the build process of an even-not-so-complex application. This is especially annoying if you have the need to compile a certain “old” programs from sources, that you may need for an impelling work task (or even for your personal project).

This is exactly what happened to me some hours ago, when I crossed the hard path of installing wmic (Windows Management Instrumentation Command-line) on a GNU/Linux machine, which I needed for an enterprise application’s backend. Yeah, I know, it may sound strange to use wmic on a non-Microsoft environment, but our test machines run Ubuntu 16.04 and our production environment consists of a set of SUSE Linux Enterprise Server 11, and adding another virtualization layer wasn’t an option.

First of all, you have to be sure to install the autoconf package.
For Debian/Ubuntu/etc:

$ sudo apt-get install autoconf

For Suse:

# zypper install autoconf

The common way of instaling wmic can be resumed in this gist:

Plain old bash shell right? Right, but if you try to run this script on a not-so-frequently updated system it’ll complain that he couldn’t achieve the installation during the sudo make execution. Here’s the summary of the failed-installation log:

Admit it, everyone hates when build from source fails. So, what’s the source of this failure?

If you take an accurate look at this part of the log (it’s only 35 rows long, don’t be lazy) you can find this specific line, which gives us the most precious debug info we could have ever desired:

Can’t use ‘defined(@array)’ (Maybe you should just omit the defined()?) at ./pidl/pidl line 583.

That “pidl” file at “wmi-1.3.14/Samba/source/pidl” is a perl source file which apparently doesn’t seem to have the most standard compliant code. After having googled for quite some time, I found this page in the official Perl Language Website. Here’s what I was looking for:

Can’t use ‘defined(@array)’ (Maybe you should just omit the defined()?)
(F) defined() is not useful on arrays because it checks for an undefined scalar value. If you want to see if the array is empty, just use if (@array) { # not empty } for example.

I haven’t ever used Perl, but the instruction at line 583 of the “pidl” file seemed useless to me, so I just got rid of it and saved.

The fastest way of doing this simple task is executing the following command on the terminal (this is particularly useful is you are in an SSH session):

sudo sed -e ‘583d’ pidl > pidl

What next? Simply re-execute the prior “sudo make” command and you’re done!

Please let me know if this was useful to you. You can find me both on Github and Twitter.