简体   繁体   English

Perl:为什么会出现错误“文件名,目录名或卷标签语法不正确。”

[英]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.

相关问题 文件名、目录名或卷标语法不正确。 (代码:123) - The filename, directory name, or volume label syntax is incorrect. (code: 123) 为什么spark-shell失败并且“文件名,目录名或卷标语法不正确。”? - Why does spark-shell fail with “The filename, directory name, or volume label syntax is incorrect.”? 为什么 spark-submit 失败并显示“文件名、目录名或卷标语法不正确。”? - Why does spark-submit fail with “The filename, directory name, or volume label syntax is incorrect.”? 从GUI应用程序使用CreateProcess运行.bat脚本会导致“文件名,目录名或卷标签语法不正确。”错误 - Running a .bat script with CreateProcess from a GUI app results in “The filename, directory name, or volume label syntax is incorrect.” error Mercurial错误“文件名,目录名称或卷标语法不正确” - Mercurial error “The filename, directory name, or volume label syntax is incorrect” 如何修复错误“文件名、目录名或卷标语法不正确”? - How to fix error “The filename, directory name, or volume label syntax is incorrect”? 错误:mkdir…文件名,目录名称或卷标签语法不正确 - Error: mkdir … The filename, directory name or volume label syntax is incorrect 批处理中的文件名、目录名或卷标语法不正确 - The filename, directory name, or volume label syntax is incorrect inside batch CMD 中的“C:\”、文件名、目录名或卷 label 语法不正确 - 'C:\' in CMD, the filename, directory name, or volume label syntax is incorrect OSError: [WinError 123] 文件名、目录名或卷 label 语法不正确: - OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM