[英]Perl: Why do I get error “The file name, directory name, or volume label syntax is incorrect.”
I am trying to run the below perl code from Windows batch file but getting error The file name, directory name, or volume label syntax is incorrect.
我正在尝试从Windows批处理文件运行以下perl代码,但出现错误
The file name, directory name, or volume label syntax is incorrect.
The script ran fine in eclipse.My ultimate goal is to run this perl script periodically using windows task scheduler, hence running it from a batch file. 该脚本在eclipse中运行良好。我的最终目标是使用Windows Task Scheduler定期运行此perl脚本,从而从批处理文件运行它。
Is there any other ways with which we can achieve my goal of running perl script on windows periodically? 还有其他方法可以实现定期在Windows上运行Perl脚本的目标吗?
I want my script to be functional across platforms, coz I have plans to run it from a mac as well. 我希望我的脚本能在所有平台上正常工作,因为我也计划从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;
If that is exactly the contents of your file, then you're asking Windows' command interpreter to process Perl source code, which it can't do 如果这恰好是文件的内容,那么您是在要求Windows的命令解释器处理Perl源代码,而源代码无法执行
If you really need to create a batch file that has your Perl code embedded in it, then take a look at the pl2bat
utility, which will do exactly that 如果您确实需要创建一个嵌入了Perl代码的批处理文件,那么请看一下
pl2bat
实用程序,它可以做到这一点。
A command like 像这样的命令
pl2bat myperl.pl
will create a file myperl.bat
that will run on the Windows command line and has your Perl source code embedded inside it. 将创建文件
myperl.bat
,该文件将在Windows命令行上运行,并在其中嵌入您的Perl源代码。 But that file is non-portable because it uses Windows commands that aren't recognised on a Mac or Linux platform 但是该文件不可移植,因为它使用Mac或Linux平台上无法识别的Windows命令
Either something doesn't know how to execute your Perl script, or your Perl script is being interpreted by something other than perl
. 无论是什么不知道如何执行你的Perl脚本,或者你的Perl脚本是由比其他的东西解释
perl
。
This could due to a problem with your file associations (or a lack thereof). 这可能是由于文件关联出现问题(或缺少文件关联)。 Determining the exact cause would require more information.
确定确切原因将需要更多信息。
In any case, executing perl
with your script as a parameter rather than executing the script directly should solve the problem. 无论如何,以脚本作为参数执行
perl
而不是直接执行脚本应该可以解决问题。
In other words, execute 换句话说,执行
perl script.pl
instead of 代替
script.pl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.