我对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/2014My 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.
更多推荐
发布评论