【发布时间】:2016-06-09 22:41:39
【问题描述】:
我正在尝试从 Windows 批处理文件运行以下 perl 代码,但出现错误 The file name, directory name, or volume label syntax is incorrect.
该脚本在 Eclipse 中运行良好。我的最终目标是使用 Windows 任务调度程序定期运行这个 perl 脚本,从而从批处理文件中运行它。
有没有其他方法可以实现我在 Windows 上定期运行 perl 脚本的目标?
我希望我的脚本能够跨平台运行,因为我也计划在 Mac 上运行它。
use strict;
use warnings;
use Data::Dumper;
use File::Find::Rule;
my $basedir="G:\/My_Workspaces";
my @exclude_dirs= qw(.foo);
#Fetching all the workspaces under base dir excluding the ones in @exclude_dirs
my @subdirs =
File::Find::Rule
->mindepth(1)
->maxdepth(1)
->not_name(@exclude_dirs)
->directory
->in($basedir);
#Formating list of workspaces by removing the full path
s{^\Q$basedir\E/}{} for @subdirs;
【问题讨论】:
-
除非此文件中的内容比您显示的更多,否则它是 Perl 源文件,而不是 Windows 批处理文件。这正是你所拥有的吗?另外请注意,只有 Windows 支持像
G:\My_Workspaces这样的卷号 -
@Borodin :变量
$basedir的值将在 mac 上发生变化。这是我的 perl 代码中唯一使用目录名称的部分。知道为什么我会收到错误吗?谢谢! -
不要转义
/,这是一个正常的字符。X:/foo/bar应该可以在 Windows 上运行。 -
该错误消息是来自 Perl 还是来自 Windows?此外,您无需从批处理文件调用脚本即可通过 Windows 计划任务调用它。
标签: windows perl batch-file