如何使用perl脚本通过.bat文件在文件夹中运行.exe文件集

时间:2021-11-24 02:07:15

I am beginner to Perl and I have to create a .pl file and I have folder containing near about 30 exe files(inside Folder1 in G:\Folder1). All of them must be executed by click to the .pl file.

我是Perl的初学者,我必须创建一个.pl文件,我的文件夹包含大约30个exe文件(在G:\ Folder1中的Folder1内)。必须通过单击.pl文件执行所有这些操作。

My try is :

我的尝试是:

   use strict; use warnings;
use autodie;  # automatic error handling

while (defined(my $file = glob 'C:\shekhar_Axestrack_Intern*.exe')) 
{
  open my $fh, "<", $file;  # lexical file handles, automatic error handling

  while (defined( my $line = <$fh> )) {
    do system $fh ; 

  }
  close $fh;
}

Please let me know if my logic correct ? Could some one please correct me if i am wrong ?

如果我的逻辑正确,请告诉我?如果我错了,有人可以纠正我吗?

2 个解决方案

#1


1  

Use system to execute an exe:

使用系统执行exe:

while (my $file = glob 'C:\shekhar_Axestrack_Intern\*.exe') {
  system $file;
}

In addition, I have the feeling that you meant to write 'C:\shekhar_Axestrack_Intern*.exe' instead of 'C:\shekhar_Axestrack_Intern*.exe'.

另外,我觉得你打算写'C:\ shekhar_Axestrack_Intern * .exe'而不是'C:\ shekhar_Axestrack_Intern * .exe'。

#2


1  

I think pl2bat may help you. It allows you to wrap Perl code into a batch file.

我认为pl2bat可能对你有帮助。它允许您将Perl代码包装到批处理文件中。

BTW why are you using echo in your Perl script? You should use print.

为什么你在Perl脚本中使用echo?你应该使用print。

Edit: You have edited your question and now you want to know how to run all exe files from a folder using Perl?

编辑:您已编辑了您的问题,现在您想知道如何使用Perl从文件夹运行所有exe文件?

Use the system command to run the exe files providing the full path.

使用system命令运行提供完整路径的exe文件。

See: How to run an executable file using Perl on Windows XP?

请参阅:如何在Windows XP上使用Perl运行可执行文件?

Edit 2: do system $fh ; This is not how you do it, please get a book (I'd suggest Beginning Perl by Ovid) and start learning Perl.

编辑2:做系统$ fh;这不是你怎么做的,请拿一本书(我建议由Ovid开始Perl)并开始学习Perl。

#1


1  

Use system to execute an exe:

使用系统执行exe:

while (my $file = glob 'C:\shekhar_Axestrack_Intern\*.exe') {
  system $file;
}

In addition, I have the feeling that you meant to write 'C:\shekhar_Axestrack_Intern*.exe' instead of 'C:\shekhar_Axestrack_Intern*.exe'.

另外,我觉得你打算写'C:\ shekhar_Axestrack_Intern * .exe'而不是'C:\ shekhar_Axestrack_Intern * .exe'。

#2


1  

I think pl2bat may help you. It allows you to wrap Perl code into a batch file.

我认为pl2bat可能对你有帮助。它允许您将Perl代码包装到批处理文件中。

BTW why are you using echo in your Perl script? You should use print.

为什么你在Perl脚本中使用echo?你应该使用print。

Edit: You have edited your question and now you want to know how to run all exe files from a folder using Perl?

编辑:您已编辑了您的问题,现在您想知道如何使用Perl从文件夹运行所有exe文件?

Use the system command to run the exe files providing the full path.

使用system命令运行提供完整路径的exe文件。

See: How to run an executable file using Perl on Windows XP?

请参阅:如何在Windows XP上使用Perl运行可执行文件?

Edit 2: do system $fh ; This is not how you do it, please get a book (I'd suggest Beginning Perl by Ovid) and start learning Perl.

编辑2:做系统$ fh;这不是你怎么做的,请拿一本书(我建议由Ovid开始Perl)并开始学习Perl。