# Perl on Windows question

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

I have ActiveState perl installed on my PC and have discovered an odd
behavior when executing a "type" command, e.g.,

system "type c:\somefile";

This comes back with the error

However, when I use this form

system "cmd /c type c:\somefile";

it works as expected. I've only seen problem happen with the type
command. Other built in commands appear to work properly. Other users
in the comany do not see this error either, even with the type command.
What would be causing this in my environment?

## Re: Perl on Windows question

pwste...@bigfoot.com wrote:

command.

You know, I've seen this error, too.  For example, if I have a file
named "file.txt" in my current directory and I'm writing a Perl
one-liner (and I'm too lazy to use the open() function), I'll sometimes
use backquotes to read the text into a variable.

For example, this Perl one-liner fails:

perl -e "print type theory.txt"

The error message it gives is:

But then, as you suggested, I try:

perl -e "print cmd /c type file.txt"

then everything works correctly.

Unfortunately, I don't know why in the world the DOS "type" command
is behaving this way.  In case anyone is interested, my "perl -v"
output is:

This is perl, v5.8.2 built for MSWin32-x86-multi-thread
(with 25 registered patches, see perl -V for more detail)
Binary build 808 provided by ActiveState Corp.
http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Dec  9 2003 10:19:40

I don't think any of this information helps you at all, other than
letting you know that you aren't the only one who has experienced this
strange behavior.  But if anyone figures out why it's behaving this

Thanks.

-- Jean-Luc

## Re: Perl on Windows question

Are sure it is the cmd built-in 'type' that you are calling?

Sinan

## Re: Perl on Windows question

These replies gave me the clue I needed. No, I don't have cygwin
installed, but I do have a bin directory with a bunch of Unix-style
commands, including type.exe. When I run from a command line, the
command shell recognizes type as a built-in command first before
looking in the search path. When running from Perl though, if looks at
the search path first. So, I just got rid of the type.exe command since
I don't need it.

Thanks for the help.

Peter

## Re: Perl on Windows question

> These replies gave me the clue I needed. No, I don't have cygwin
> installed, but I do have a bin directory with a bunch of Unix-style
> commands, including type.exe. When I run from a command line, the
> command shell recognizes type as a built-in command first before
> looking in the search path. When running from Perl though, if looks at
> the search path first. So, I just got rid of the type.exe command since
> I don't need it.
>

You could also get the desired result with:
system "type c:\somefile <NUL";

Any redirects will ensure that the shell built-ins are searched first.

Cheers,
Rob

## Re: Perl on Windows question

A. Sinan Unur wrote:

Wow.  I think you just helped me solve my problem, Sinan.

I tried "which type.exe" (I have "which" on Win32 because I
installed a set of Unix Utilities) and discovered that the "type"
program that Perl was using in backticks was the Unix-ish "type"
program, not the DOS built-in "type" command.

I temporarily renamed the "type.exe" Unix-ish program and tried
running the Perl one-liner:

perl -e "print type file.txt"

and then it worked!  Then I restored the Unix-ish "type.exe" program
and tried the two following commands at the DOS prompt:

> type file.txt
> full\path\to\Unix\Utils\type file.txt

and discovered that the first command worked like the Unix "cat"
command, but the second line returned the following error:

which was the same error message the original poster was getting in the
first place.

So, apparently, when I use "type" from the DOS command line, it uses
the built-in DOS command, but if I use it from a Perl backtick (or
system()) call, it uses the one in the Unix Utilities (which is in my
%PATH%).

The work-around to this problem is to replace "type" with "cat"
(which I should have since I installed the Unix Utilities).  Of course,
this makes my Perl one-liners less portable across Win32 systems -- but
then, it's not a difficult thing to change, considering that Perl
one-liners are only one line of code (or so).

Anyway, thank you for helping me find the problem, Sinan.  I hope my
explanation was clear enough to understand.

-- Jean-Luc

## Re: Perl on Windows question

....

You are welcome. I was almost certain the issue was a confusion between the
cmd.exe builtin versus an executable in the path, but needed more
information.

Sinan

## Re: Perl on Windows question

pwsteele@bigfoot.com wrote in news:1115051456.160919.23370

Well, the crucial question is whether c:\somefile exists, right?

On the other hand, the error message above does not seem to be from the cmd
built-in. Do you, maybe, have cygwin installed, with the command line
utility type installed in your path?

Great question. Only you can know as we know nothing about your
environment.

Sinan