简体   繁体   English

为什么Perl中的反引号运算符在Windows上没有引号时无效?

[英]Why is the backticks operator in Perl not working without the quotes on Windows?

I'm pretty new to Perl, so forgive me if the question is trivial. 我对Perl很新,所以请原谅我这个问题是微不足道的。

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. 整个事情必须在Windows上工作,使用Strawberry Perl,我使用windows命令date /T来执行日期检查。 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. 如果使用反引号的其他外部调用将起作用,我会得到它,但这是我必须以这种方式调用的唯一一个,以使其工作。

You seem to be accidentally using the Cygwin/GnuTools version of date . 您似乎无意中使用了Cygwin / GnuTools版本的date

Under a Windows command prompt, date /T gives the current time. 在Windows命令提示符下, date /T给出当前时间。
This is not an executable, this is a command . 这不是可执行文件,这是一个命令

However, running date /T under the Cygwin/GnuTools environment gives date: invalid date '/T' . 但是,在Cygwin / GnuTools环境下运行date /T会给出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. 这是因为环境1)无法看到Windows date 命令2)PATH环境变量中找到可执行 date并改为运行它。

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

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