windows - Perl:为什么我会收到错误 "The file name, directory name, or volume label syntax is incorrect."

标签 windows perl batch-file

我正在尝试从 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;

最佳答案

如果这正是您文件的内容,那么您是在要求 Windows 的命令解释器处理 Perl 源代码,这是它做不到的

如果您真的需要创建一个批处理文件,其中嵌入了您的 Perl 代码,请查看 pl2bat实用程序,它将完全做到这一点

像这样的命令

pl2bat myperl.pl

将创建一个文件 myperl.bat,它将在 Windows 命令行上运行并将您的 Perl 源代码嵌入其中。但该文件不可移植,因为它使用了 Mac 或 Linux 平台无法识别的 Windows 命令

关于windows - Perl:为什么我会收到错误 "The file name, directory name, or volume label syntax is incorrect.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35656410/

相关文章:

windows - 从批处理文件的Behat与错误处理程序

windows - 具有内联 asm 的 Windows x64 平台中的 libsoxr 未编译

mysql - 如何将 UTF-8 数据与保存在 Latin1 MySQL 数据库表中的相同数据进行比较

perl - 如何以编程方式确定我的 Perl 程序在 Windows 下的内存使用情况?

c# - 网络层如何监听?

c++ - 为什么调用 WSASocket() vs socket() 会导致发送阻塞?

linux - find.pm 错误 "encountered a second time"

windows - 如何使用批处理文件创建 EXE 可执行文件?

batch-file - 带有 FFMPEG 的批处理 FOR 循环

dos - 我该如何修复这个批处理脚本?