APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Transferring Linux or Mac Perl scripts to Windows Cygwin

Some material is very old and may be incorrect today

© December 2015 Anthony Lawrence


I've put up quite a few Perl scripts here over the years. A number of them are for accomplishing various tasks related to Kerio products. While I certainly strongly recommend that customers choose Linux or Mac over Windows, not everyone takes my advice, which means that the Kerio related Perl scripts aren't necessarily immediately useful to everyone.

You can certainly get Windows Perl ports (Strawberry Perl, for one), but these scripts sometimes are written with a strong Linux/Unix slant and there could be a fair amount of work involved to translate them properly.


It's much easier to use Cygwin. Getting Cygwin installed might be a little more difficult than typical Windows packages, but it's not all that hard and, once it's done, you'll be able to easily do things that are otherwise very difficult in Windows. Cygwin is free, so let's go install it now:

Download Setup from http://cygwin.com/install.html. I suggest moving it to your Desktop or at least somewhere where you can find it easily again because this program is also used for updates and configuration.

The installation (and in future updates) will ask you for a mirror site to use for downloading. Windows people don't expect that; just select one of the listed servers and continue along.

Running%20Cygwin%20setup Cygwin%20Install%20Directory

Cygwin%20Local%20Package%20Directory Choose%20Cygwin%20download%20site


If you just choose the default install, you won't get Perl. Add it by searching for it and selecting these packages.


You are also going to want a text editor. I prefer "vim", but most people are put off by its learning curve. You can write your scripts in Windows, but you may need to translate line endings. For that, you'll also want to install the cygutils package and use the conv, d2u, dos2unix, u2d, and unix2dos programs from there. The "conv" is easy enough:

Usage: conv [OPTION...] [input file list...]

Main options (not all may apply)
  -A, --auto     Output format will be the opposite of the autodetected source
  -D, --u2d      Output will be in DOS format
  --unix2dos     Output will be in DOS format
  -U, --d2u      Output will be in UNIX format
  --dos2unix     Output will be in UNIX format
  --force        Ignore binary file detection
  --safe         Do not modify binary files

Help options
  -?, --help     Show this help message
  --usage        Display brief usage message
  --version      Display version information
  --license      Display licensing information

Other arguments
  [input file list...]       for each file listed, convert in place.
                             If none specified, then use stdin/stdout

You may not need to do that - your Cygwin shell may be set to ignore the carriage return that Windows adds to files. You WILL need it if you want to edit a Unix/Linux file in Notepad.

File paths

Generally speaking, if you see a file name in a Perl script, change it to "/cygwin/(drive)/path". You don't always need to do that - if you saw:


you could leave that alone, but if you see:


That would need changing:

open(I,"/cygdrive/c/Program Files/Kerio/mailserver/mailserver.cfg");

That's in a different location. You could get away with just "/Program Files/Kerio/mailserver/mailserver.cfg", but to avoid missing something, I suggest just changing everything.

Note that we also introduced a space into the path ("Program Files"). You have to watch out for changes like that as the original script may not have bothered to quote things that will need to be quoted when spaces are part of the name.See Cygwin: using a path variable containing a windows path (with a space in it) for further discussion.

If your files were on D:, you'd use "/cygdrive/D/whatever" and so on. If in doubt, be specific.

File names

Sometimes files exist on Windows with slightly different names. For example, a script might use "sendmail" from the Kerio mailserver directory. That script won't work on Windows because it's named "sendmail.exe" there. You'd need to either change the script or create a link from "sendmail.exe" to "sendmail".

System commands

Many Linux/unix Perl scripts use "system" to run operating system commands. Many of these will work in the Cygwin environment, but if you don't know that a particular command will work, you need to test. Sometimes you can fix a problem like that by writing a shell script that does the needed task. Other times you need to write the whole thing in Perl


The Linux/Unix script may reference Perl modules you don't have. CPAN is how you get them, but you need "make" from Cygwin setup too. You may run into other things you need; Google is your friend for those kinds of problems.

Note that I found CPAN to run much more slowly under Cygwin than it does on Linux or Mac OS X. It is so slow that I thought it was hung at times! You definitely need patience (something I don't have much of)

Help from me

If you are one of my Kerio customers (that is, you renew your licenses and buy new product from me), I will help you at no charge. Just send me the script you are trying to convert and tell me what I need to know about your environment

If you are NOT a Kerio customer, I might be willing to help you on a charge basis but my regular customers come first, always. If your project will require more than a few minutes of time, I might have to turn you down (unless you'd like to become on of my customers, of course).

If you found something useful today, please consider a small donation.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Transferring Linux or Mac Perl scripts to Windows Cygwin


Inexpensive and informative Apple related e-books:

Are Your Bits Flipped?

iOS 10: A Take Control Crash Course

Take Control of iCloud, Fifth Edition

Take Control of OS X Server

Take control of Apple TV, Second Edition

More Articles by © Anthony Lawrence

Sun Oct 14 01:29:50 2012: 11381   anonymous


Thank you, that was interesting. I personally use python for scripting, and loath working on windows, but sometimes I have to with some legacy software at work. Do you think cygwin will stay alive and supported, with this virtual machine business? If only everybody would use Mac or Linux/Unix...

Sun Oct 14 10:58:55 2012: 11382   TonyLawrence


I think Cygwin will survive as long as Windows does.. it's a big help for those Windows admins smart enough to take advantage of it.


Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

C++: an octopus made by nailing extra legs onto a dog. (Steve Taylor)

Linux posts

Troubleshooting posts

This post tagged:


Kerio Info

Kerio Pricing

Kerio RSS Feed




Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode