-1

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.

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 ?

user3085082
  • 133
  • 4
  • 16
  • Perl and Batch are completely different languages. Did you want the batch script to call the Perl script? – SomethingDark Jan 06 '15 at 05:26
  • @SomethingDark actually i have already done it through .bat script but what happens when i launch the .exe file through .bat click then it popups a GUI which conmtains some button. My mentor wants those button to be clicked automatically by my code. He suggested me to use perl for that. But i have no idea how to click that button by simple click to .bat file. (I mean on click to that .bat file must execute all .exe files each of which pop ups a GUI and on also contain a button on GUI, that click to .bat file must not just launch the .exe GUI but also click the button on GUI automatically) – user3085082 Jan 06 '15 at 05:32
  • Currently using batch script i am just able to run all .exe but i need to manually click on the button of the GUI obtained through each of these .exe. But my mentor told me that using perl you can automatically get a click to the buttons present on the GUI obtained on each .exe file launched by click to .bat file. – user3085082 Jan 06 '15 at 05:37
  • 2
    Automating GUI interaction isn't easy in any language. Googling "perl interact with gui" suggests using the Win32::GuiTest Perl module. You may also be able to brute-force something with either PowerShell or VBScript. – SomethingDark Jan 06 '15 at 05:43
  • @SomethingDark .. Thanks. I was misunderstood.. there is nothing like .bat file. could you please let me know how to run all .exe file in Folder1 using perl code ? (By recorrecting my code) ? – user3085082 Jan 06 '15 at 06:03
  • Sorry, I don't know Perl. I recommend searching Google for "Perl run executable" or something similar. – SomethingDark Jan 06 '15 at 06:12

2 Answers2

1

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

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

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

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

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

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.

Community
  • 1
  • 1
Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133
  • thanks but could you please see last two comments i done to reply SomethingDark ? to know what i want to achieve . – user3085082 Jan 06 '15 at 05:41
  • so could you please correct the problem in my code , so that i will be ble to run all .exe files in the Folder1 using perl code? After i will try myselt to find a way to get GUI control using perl – user3085082 Jan 06 '15 at 05:47
  • I have used do system($fh) ; still do not work (to run each exe file in folder) , it still do not work but it is error free . Could you please correct me how to achieve it ? – user3085082 Jan 06 '15 at 06:17
  • Try using `$line` instead of `$fh` – SomethingDark Jan 06 '15 at 06:22
  • @SomethingDark it keeps on running terminal infinitely.. some strange things .. Not launching exes – user3085082 Jan 06 '15 at 06:40
1

Use system to execute an 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'.

René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293