为什么Perl中的反引号操作符在Windows上没有引号时无效?(Why is the backticks operator in Perl not working without the quote

编程入门 行业动态 更新时间:2024-10-25 06:20:05
为什么Perl中的反引号操作符在Windows上没有引号时无效?(Why is the backticks operator in Perl not working without the quotes on Windows?)

我对Perl很新,所以请原谅我这个问题是微不足道的。

在工作中,我有一个创建脚本的任务,当其他开发人员错过任务的截止日期时,该脚本将发送电子邮件。 整个事情必须在Windows上运行,使用Strawberry Perl,我使用windows命令date /T来执行日期检查。 我使用反引号运算符调用了很多外部命令,但在这种特殊情况下,反引号不起作用:

my $date = `date /T`;

输出:

date: invalid date `/T'

固定使用一些额外的报价:

my $date = `"date /T"`

输出:

Mon 07/07/2014

我的问题是:为什么?

如果使用反引号的其他外部调用将起作用,我会得到它,但这是我必须以这种方式调用的唯一一个,以使其工作。

I'm pretty new to Perl, so forgive me if the question is trivial.

At work I have got an assignment to create a script which would send out e-mails when other developers would miss the due date of their tasks. As whole thing would have to work on Windows, using Strawberry Perl, I have used windows command date /T to perform the date check. I have called external commands quite a lot, using the backticks operator, but in this particular case the backticks would not work:

my $date = `date /T`;

Outputs:

date: invalid date `/T'

Fixed using some additional quotes:

my $date = `"date /T"`

Outputs:

Mon 07/07/2014

My question is: why is that?

I would get that if the other external calls with backticks would work the same, but that's the only one I have to call that way, to make it work.

最满意答案

您似乎意外地使用了Cygwin / GnuTools版本的date 。

在Windows命令提示符下, date /T给出当前时间。 这不是可执行文件,这是一个命令

但是,在Cygwin / GnuTools环境下运行date /T会给出date: invalid date '/T' 。 这是因为环境1)无法看到Windows date 命令2)在其PATH环境变量中找到可执行 date并改为运行它。

You seem to be accidentally using the Cygwin/GnuTools version of date.

Under a Windows command prompt, date /T gives the current time. This is not an executable, this is a command.

However, running date /T under the Cygwin/GnuTools environment gives date: invalid date '/T'. This is because the environment 1) cannot see the Windows date command and 2) finds a date executable in their PATH environment variable and runs it instead.

更多推荐

本文发布于:2023-08-04 07:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412434.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:引号   操作   Windows   Perl   working

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!