Windows 10 上的 Perl 脚本从资源管理器运行,但不是命令提示符 [英] Perl Scripts on Windows 10 run from Explorer but not Command Prompt

查看:27
本文介绍了Windows 10 上的 Perl 脚本从资源管理器运行,但不是命令提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的新 Windows 10 PC 上安装了 ActiveState Perl.我已经在我自己的几台 PC 上安装了完全相同版本的 Perl,并且它安装在我公司的 100 台其他用户的 PC 上.完全相同的安装,由我创建.

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.

这是第一次在 Windows 10 上尝试此操作.在资源管理器中双击 Perl 脚本 (*.pl) 的基本操作会导致控制台窗口打开并让 Perl 运行脚本.

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.

另外,在 Windows 命令提示符中,我可以输入 perl.exe script.pl,脚本运行良好.但是,当我只输入 script.pl 时,什么也没有发生.没有输出,没有错误,在任务管理器中看不到 perl.exe 进程.

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.

当我第一次运行 Perl 脚本时(我相信,来自 Windows 命令提示符,只使用 script.pl 语法),Windows 弹出一个窗口,询问我想使用什么程序打开这个文件.Perl 是默认设置,我点击了确定.

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.

我从未在 Windows 7 或 8 中看到过该窗口,所以我认为它是 Windows 10 特有的,并且它以某种方式阻止我输入 script.pl.因为,在启动 script.pl 时,我需要文件关联来选择正确的程序,但是当我键入 perl.exe script.pl 时,perl.exe 是直接启动.但是,当从命令提示符运行时,Windows 10选择你的默认程序"的事情会因为弄乱文件关联而受到阻碍.

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.

虽然不能 100% 确定它为什么可以在 Explorer 中运行,但我很确定我需要清除该默认程序.我删除了 HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts 下的 .pl 文件的注册表项,但这没有帮助.

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_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts, but that didn't help.

这似乎是 Windows 10 的一个更普遍的问题,或者可能只是我安装的问题,或者我不知道的组策略.

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.

以下命令(在管理员命令提示符下运行)在 Windows 8.1 中运行良好,但在 Windows 10 中运行良好:

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:WINDOWSsystem32foo.bat %1
echo @echo off > foo.bat
echo echo The filename is %1 >> foo.bat
echo hi > foo.foo
foo.foo

结果应该是输出:

The filename is C:WINDOWSsystem32foo.foo

但是 Windows 10 什么都不做.它似乎只允许以这种方式关联内置应用程序,而不是下载/安装的 EXE 的 BAT 脚本.

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.

推荐答案

原来微软在 Windows 10 中颠倒了注册表设置的极性,这也让其他 Perl 程序员感到痛苦.解决方案是将 HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerInheritConsoleHandles 设置为0".

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_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerInheritConsoleHandles to "0".

MSDN 在此处发布:https://social.msdn.microsoft.com/Forums/en-US/f19d740d-21c8-4dc2-a9ab-d5c0527e932b/nasty-file-association-regression-Windows-10-控制台中的错误

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

这篇关于Windows 10 上的 Perl 脚本从资源管理器运行,但不是命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆