如何修复 Windows 上的“无法识别 perl”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2129959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I fix "perl is not recognized" on Windows?
提问by rrrfusco
I've set up a log file to pick up MySQL slow queries.
我已经设置了一个日志文件来获取 MySQL 慢查询。
I've been unable to parse the file however. Linux makes this task seem very simple. In tutorials it seems as easy as:
但是,我一直无法解析该文件。Linux 使这个任务看起来非常简单。在教程中,它看起来很简单:
$ mysqldumpslow -s c -t 10
In Windows however, I'm not sure how you run Perl, located in: G:\xampp\perl\binwith the Perl Script mysqldumpslow.pl, located in: G:\xampp\mysql\scripts
但是,在 Windows 中,我不确定您如何运行 Perl,位于:G:\xampp\perl\bin和 Perl 脚本mysqldumpslow.pl,位于:G:\xampp\mysql\scripts
I've tried to enter:
我试过输入:
G:\xampp\mysql\scripts\perl mysqldumpslow -s c -t 10
G:\xampp\mysql\scripts\perl mysqldumpslow -sc -t 10
The command prompt returns something like "perl is not recognized".
命令提示符返回类似“无法识别 perl”的内容。
回答by Alex Budovski
Errm, you are using the wrong paths.
呃,你使用了错误的路径。
If perl.exe is located in G:\xampp\perl\bin and the mysql script in G:\xampp\mysql\scripts, you need:
如果 perl.exe 位于 G:\xampp\perl\bin 且 mysql 脚本位于 G:\xampp\mysql\scripts,则需要:
> G:\xampp\perl\bin\perl G:\xampp\mysql\scripts\mysqldumpslow.pl -s c -t 10.
Of course, that's a very roundabout way of doing things, so instead, add perl to your PATH, and cd
into the correct directory and then run it:
当然,这是一种非常迂回的做事方式,因此,相反,将 perl 添加到您的 PATH,并添加cd
到正确的目录中,然后运行它:
> set PATH=G:\xampp\perl\bin\;%PATH% // Note: This can be added in the
// System Control Panel.
> cd /d G:\xampp\mysql\scripts
> perl mysqldumpslow.pl -s c -t 10
Or even better, add perl to your known filetypes.
或者更好的是,将 perl 添加到您已知的文件类型中。
- Go to Explorer -> Tools -> Folder Options -> File Types.
- Click 'New', type
pl
for the extension field. Click Ok. - Find PL in your list, click Advanced. Under Actions, click 'New'.
For Action type
open
, for 'Application used to perform action' type:G:\xampp\perl\bin\perl.exe -w "%1" %*
Click Ok.
- 转到资源管理器 -> 工具 -> 文件夹选项 -> 文件类型。
- 单击“新建”,输入
pl
扩展字段。单击确定。 - 在列表中找到 PL,单击高级。在操作下,单击“新建”。
对于操作类型
open
,对于“用于执行操作的应用程序”类型:G:\xampp\perl\bin\perl.exe -w "%1" %*
单击确定。
Now you can just run the script as:
现在您可以将脚本运行为:
> mysqldumpslow.pl -s c -t 10
As you would in Linux.
就像在 Linux 中一样。
Quick note: Adding .pl files as known file types is roughly equivalent to Unix people adding
快速说明:将 .pl 文件添加为已知文件类型大致相当于 Unix 人添加
#!/usr/bin/perl -w
to the start of every perl script. In Windows you only need to add it once.
到每个 perl 脚本的开头。在 Windows 中,您只需添加一次。
Second note: The -w
turns on Warnings in the perl interpreter. You can leave out the -w
if you wish.
第二个注意事项:-w
在 perl 解释器中打开警告。-w
如果你愿意,你可以省略。
回答by Parikshit
I fixed this error by using the command:
我使用以下命令修复了此错误:
set PATH=C:\perl\bin;%PATH%
回答by ghostdog74
if your Perl interpreter perl.exe is located in G:\xampp\perl\bin
, then use G:\xampp\perl\bin\perl.exe
. For convenience of calling your Perl interpreter from anywhere , you can add the path G:\xampp\perl\bin
into your PATH environment variable. To call your Perl script, try this
如果您的 Perl 解释器 perl.exe 位于 中G:\xampp\perl\bin
,则使用G:\xampp\perl\bin\perl.exe
. 为了方便从任何地方调用 Perl 解释器,您可以将路径添加G:\xampp\perl\bin
到 PATH 环境变量中。要调用你的 Perl 脚本,试试这个
c:\> G:\xampp\perl\bin\perl.exe G:\xampp\mysql\scripts\mysqldumpslow.pl