简体   繁体   English

如何在Windows上修复“perl未被识别”?

[英]How do I fix “perl is not recognized” on Windows?

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. Linux使这项任务看起来非常简单。 In tutorials it seems as easy as: 在教程中,它似乎很简单:

 $ mysqldumpslow -s c -t 10

In Windows however, I'm not sure how you run Perl, located in: G:\\xampp\\perl\\bin with 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 -sc -t 10 G:\\ xampp \\ mysql \\ scripts \\ perl mysqldumpslow -sc -t 10

The command prompt returns something like "perl is not recognized". 命令提示符返回“perl is not recognized”之类的内容。

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和G:\\ xampp \\ mysql \\ scripts中的mysql脚本,则需要:

> 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添加到您已知的文件类型中。

  1. Go to Explorer -> Tools -> Folder Options -> File Types. 转到资源管理器 - >工具 - >文件夹选项 - >文件类型。
  2. Click 'New', type pl for the extension field. 单击“新建”,键入pl作为扩展字段。 Click Ok. 单击确定。
  3. Find PL in your list, click Advanced. 在列表中找到PL,单击“高级”。 Under Actions, click 'New'. 在“操作”下,单击“新建”。
  4. For Action type open , for 'Application used to perform action' type: 对于Action类型open ,对于'用于执行操作的应用程序'类型:

    G:\\xampp\\perl\\bin\\perl.exe -w "%1" %*

  5. Click Ok. 单击确定。

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. 到每个perl脚本的开头。 In Windows you only need to add it once. 在Windows中,您只需添加一次。

Second note: The -w turns on Warnings in the perl interpreter. 第二个注意事项: -w在perl解释器中打开警告。 You can leave out the -w if you wish. 如果你愿意,你可以省略-w

我使用以下命令修复了此错误:

set PATH=C:\perl\bin;%PATH%

if your Perl interpreter perl.exe is located in G:\\xampp\\perl\\bin , then use G:\\xampp\\perl\\bin\\perl.exe . 如果您的Perl解释器perl.exe位于G:\\xampp\\perl\\bin ,则使用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. 为了方便从任何地方调用Perl解释器,可以将路径G:\\xampp\\perl\\bin到PATH环境变量中。 To call your Perl script, try this 要调用Perl脚本,请尝试此操作

c:\> G:\xampp\perl\bin\perl.exe G:\xampp\mysql\scripts\mysqldumpslow.pl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM