6

I've installed ActiveState Perl on my new Windows 10 PC. I've installed the same exact version of Perl on several of my own PC's, and it's installed on 100's of other users' PC's in my company. Same exact install, created by me.

This is the first time trying this on Windows 10. The basic actions of double-clicking a Perl script (*.pl) in Explorer cause a console window to open and Perl to run the script.

Also, in Windows Command Prompt, I can type perl.exe script.pl, and the script runs fine. But, when I just type script.pl, nothing happens. No output, no errors, no perl.exe processes visible in Task Manager.

The first time I ran a Perl script (from Windows Command Prompt, I believe, using just the script.pl syntax), Windows popped up a window asking me what program I wanted to use to open this file. Perl was the default, and I clicked OK.

I've never seen that window in Windows 7 or 8, so I'm thinking it's something specific to Windows 10, and that it's the thing that's somehow preventing me from just typing script.pl. Because, when launching script.pl, I'm requiring the file associations to pick the right program, but when I type perl.exe script.pl, perl.exe is being launched directly. But, that Windows 10 "pick your default program" thing is getting in the way when running from the command prompt by messing up the file associations.

Not 100% sure why it works from Explorer, though, but I'm pretty sure that I need to clear that default program thing. I removed the registry entry for .pl files under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts, but that didn't help.

This seems to be a more generic problem with Windows 10, or possibly just my installation of it, or a Group Policy I'm not aware of.

The following commands (run in a Admin command prompt) work fine in Windows 8.1 but not Windows 10:

assoc .foo=Foobar
ftype Foobar=C:\WINDOWS\system32\foo.bat %1
echo @echo off > foo.bat
echo echo The filename is %1 >> foo.bat
echo hi > foo.foo
foo.foo

The result should be the output:

The filename is C:\WINDOWS\system32\foo.foo

But Windows 10 does nothing. It seems to only allow built-in apps to be associated in this manner, and not BAT scripts of downloaded/installed EXEs.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
jimtut
  • 2,366
  • 2
  • 16
  • 37
  • What happen if we use `start script.pl` – Harshavardhan Konakanchi Aug 11 '16 at 04:07
  • Using `start script.pl` works fine. – jimtut Aug 11 '16 at 04:10
  • I uninstalled Perl 5.20.2, and installed the latest (5.24.0), but no change. I also changed the command in the registry to open notepad.exe instead of perl.exe, and that work right from DOS (`script.pl`). It seems that something is messed up with associations that call perl.exe, although only from DOS, not Explorer. Is it possible that it's calling wperl.exe somehow? Can't find it in the registry though... – jimtut Aug 11 '16 at 04:52
  • 1
    I don't think this is specific to Perl. I created a new extension (.bar) and associated it with a simple BAT script that echo's "hi" and then pauses. Works fine from Explorer, but "script.bar" does nothing. So I don't think Perl is affecting this, but instead that I can't create associations to anything other than "notepad", and other items in C:\Windows. Is this some other Windows 10 or GPO restriction? – jimtut Aug 11 '16 at 05:47

2 Answers2

4

Turns out that Microsoft reversed the polarity of a Registry setting in Windows 10, and this is biting other Perl programmers too. The solutions is to set HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\InheritConsoleHandles to "0".

MSDN post here: https://social.msdn.microsoft.com/Forums/en-US/f19d740d-21c8-4dc2-a9ab-d5c0527e932b/nasty-file-association-regression-bug-in-windows-10-console

jimtut
  • 2,366
  • 2
  • 16
  • 37
  • Do you happen to know if something has changed for Windows 10 / 2009 (Build 19042)? This solution does not seem to work on my machine with that Windows version. – René Nyffenegger Jul 31 '21 at 21:35
-1

Make sure your PATHEXT environment variable has .pl in it.

Vince
  • 1
  • Yes, it does: `PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PL` – jimtut Aug 11 '16 at 12:39
  • 2
    PATHEXT is only needed to allow you to drop the extension from a filename and still be able to execute it. You can "run" any file, even a JPG, just by typing it's filename in DOS. – jimtut Aug 11 '16 at 12:49