Perl for Win32 Frequently Asked Questions (FAQ)

Main Page

4. Windows NT and Windows 95

4.1. Where can I get general information on Windows NT?

A good starting place is the print documentation that came with Windows NT and on the Windows NT CD in the support\books directory. Windows Help files are also available.

You can get some in-depth information on Windows NT from the Windows NT Resource Kit, available at bookstores and from Microsoft. Microsoft TechNet is also a valuable resource.

World Wide Web support for Windows NT Server is at:

http://www.microsoft.com/ntserver/

Support for Windows NT Workstation is at:

http://www.microsoft.com/ntworkstation/

4.2. Where can I get general information on Windows 95?

Print documentation comes with Windows 95, as well as some documentation on the CD-ROM. Help files are available from the Start menu.

The Windows 95 Resource Kit contains in-depth information on Windows 95. It's available at bookstores and software stores.

World Wide Web support for Windows 95 is at:

http://www.microsoft.com/windows95/

4.3. What's the equivalent of the shebang ("#!") syntax for Win32?

Unfortunately, Win32 platforms don't provide the shebang syntax, or anything like it. You can try one of the two following methods to run a script from the command line. If all else fails, you can always just call the perl interpreter directly ("perl myscript.pl").

For Windows NT 4.0, the coolest method is to use associated file types (see question 4.10). If you've associated Perl scripts with the .pl extension, you can just type the name of your file at the command line and Windows NT will launch perl.exe for you. If you change the PATHEXT environment variable to include .pl files, like this:

    SET PATHEXT=.pl;%PATHEXT%

you can just type the file name without an extension, and Windows NT will find the "closest" .pl file with that name. You may want to set PATHEXT in the System control panel applet rather than on the command line. Otherwise, you'll have to re-enter it each time the command prompt window closes.

Given this setup, you can have a Perl script called cat.pl that looks like this:

    while ( <> )
    {
      print;
    }

and you can invoke it on the command line like this:

    cat myfile.txt

However, you can't invoke it with I/O redirection, like this:

    cat < myfile.txt
    cat myfile.txt | more

although it looks like you should be able to. Your script can be in your path or you can provide a path to the file.

Note that this method does not work for Windows 95, nor does it work with Windows NT if you have command extensions disabled. You can, however, still start the Perl script from an Explorer window if the extension is associated with perl.

Another option is to use the pl2bat utility distributed with Perl for Win32 to "convert" your Perl script into a batch file. What this does is tag some Win32 batch language to the front of your script so that the system calls the perl interpreter on the file. It's quite a clever piece of batch coding, actually.

If you call the pl2bat utility on your Perl script "helloworld.pl", like this:

    C:> pl2bat helloworld.pl

it will produce a batch file, "helloworld.bat". You can then invoke the script just like this:

    C:> helloworld
    Hello, World!

(or whatever). You can pass command line parameters pretty easily. Your script can be in your PATH, or in another directory, and the pl2bat code will usually find it and execute it correctly. Like with file associations, however, you can't use I/O redirection.

pl2bat invokes perl.exe with the -w switch. If you don't like having the warning messages come up, and you know they're not important, you have to go in to the batch file and take the -w out yourself.

4.4. What's the equivalent of chmod for Win32?

There is no direct equivalent of the chmod tool on Win32 systems. For file attributes, you can use the ATTRIB command line tool (type HELP ATTRIB at the command line for details). For more complex permissions, see question 4.9.

For information on the chmod function, question 5.9.

4.5. What's the equivalent of sendmail for Win32?

Neither Windows 95 and Windows NT ships with a command-line SMTP client like "sendmail" in UNIX. Several exist, however. One popular one is BLAT, which is available in the Windows NT Resource Kit, and on the Web at this URL:

http://gepasi.dbs.aber.ac.uk/softw/Blat.html

Note that the command line syntax for BLAT is different from of "sendmail".

Microsoft has a port of sendmail available on their FTP site at:

ftp://ftp.microsoft.com/developr/drg/unix-to-windows/ports/sendmail/

A commercial sendmail product is available from MetaInfo, Inc., at:

http://www.metainfo.com/

There is an evaluation version available for download.

Another commercial mail product is wrmail, part of the slmail product from Seattle Labs. A free version is available at

http://www.seattlelab.com/

A Perl script for sending mail without using an external program is also available on Robin Chatterjee's Perl for Win32 page (see question 3.4).

4.6. How do I schedule jobs on Win32 platforms?

The UNIX tool 'cron' doesn't exist on Win32 platforms.

For Windows NT, a scheduling tool called AT is available [pronounced "@" -ESP]. AT doesn't use a table file, but takes command-line arguments. Note that the Schedule service must be running when your job is supposed to happen.

If you don't like the command-line version of AT, there's a GUI version, WinAT available with the Windows NT Resource Kit.

A commercial cron-like scheduler, NTcrond, is available from #ifdef software (http://www.ifdef.com/).

For Windows 95, there's a System Agent available with the Microsoft Plus! Pack. Also, there are several shareware scheduling utilities, notably LaunchPad and Metz Scheduler. These can be found on a good shareware search engine (like http://www.shareware.com/).

4.7. I need UNIX tool X. Where is it?

You might want to take a look at the help file for Windows NT and Windows 95 commands to see if there's a rough equivalent distributed with your Win32 platform. If not, and your question isn't answered above, try one of these UNIX-on-Win32 packages:

There are also several UNIXy tools available in the Windows NT Resource Kit. Finally, there are several UNIX-to-Win32 commercial packages available, including the MKS Toolkit from Mortice Kerns Systems, Inc. (http://www.mks.com/).

For general UNIX-on-NT information, see the UNIX to NT Resource Center (http://www.nentug.org/unix-to-nt/). [Any others? -ESP]

4.8. What is a Windows NT service?

On Windows NT, a service is a special kind of executable program that runs in the background. Services are used for programs that are constantly working, such as network protocols or database servers. Most WWW servers on Windows NT are implemented as services.

A service is different from other programs in several ways:

The most important thing to remember is that you have to take special steps to make resources available to services. In general, you need to make files available to the Everyone group, and you have to have environment variables (like PATH) be system environment variables.

[Some readers have pointed out that you can in fact run a service from the command line, using the "net start" command. True, but it's a lot different than running other programs from the command line -- type "net start /?" to find out how to use this command. -ESP]

4.9. How do I set permissions on a file?

Win32 platforms don't have the same mechanisms for setting permissions on files as UNIX does. For files on FAT partitions (which means all files in Windows 95), you don't have to set permissions explicitly on a file. All files are available to all users.

For files on an NTFS partition on Windows NT, you can set the security permissions on a file using the Explorer and the properties sheet of the file. Right-click on the file in Explorer, and select the Properties item on the drop-down menu. Select the Security tab, and press the Permissions button to set the Permissions on the file. Click Help for more information.

A command-line program, CACLS, will also change the permissions on a file. For more details, type HELP CACLS on the command line.

4.10. How do I associate Perl scripts with perl?

On Windows systems, "association" is the process of specifying which programs should be used for which kind of files. Files are grouped into file types, such as JPEG files or Perl scripts. The file type of a file is identified by its file name extension (all the letters after the last "." in the file name).

So, for example, we can say that there's a type of file called a text file, which has the file extension ".txt", and which is handled by the Notepad program.

Usually, Perl for Win32 programmers create a file type like "Perl Script" and associate the extension ".pl" with that type. We specify that the perl interpreter binary, perl.exe, is responsible for that file type. Several Web servers require that you associate your scripts with perl.exe before the script can be run.

On Windows 95 and Windows NT 4.0, you can create a new file type and associate the perl interpreter with it as follows:

You can test your association by double-clicking on a perl script in the Explorer window. If perl.exe starts and executes the script, things are OK.

On Windows NT 4.0, you can avoid all the hassle of the above and just type the following from the command line:

    ASSOC .pl=PerlScript
    FTYPE PerlScript=[full path to perl]\perl.exe %1 %*

For more information on these commands, type HELP FTYPE at the command prompt.

Note that for this to work you have to have command extensions enabled. (These are enabled by default; you'd know if you'd turned them off.)