http://qs321.pair.com?node_id=93302

Newguy2Perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have been tasked to convert the build scripts i use at work into perl scripts. Right now they are all batch files. Say i have a file named wanker.bat and one named blofish.exe How can i tell the perlscript to execute these? Thanks for your help
  • Comment on executing a .bat or .exe from within perl script ??

Replies are listed 'Best First'.
Re: executing a .bat or .exe from within perl script ??
by epoptai (Curate) on Jul 03, 2001 at 00:01 UTC
      I agree with epoptai that exec and system could work. There are good and bad points with each, and another possible solution that may be better for you.

      If you use 'exec batchfile.bat', it does execute that program.. but it never returns to the currently running program. The current program exists right there and then. Sometimes, that is what you want.

      If you use 'system batch.bat', your current program forks to run that program, and then returns. However, the return value that it returns to your program is NOT the output of the program it ran, but instead returns the program's exit status. Sometimes, this is what you want.

      If you want to run a program, and retrieve that programs output, you need to use backticks, such as:
      my $output = `batchfile.bat`;
      That will run the batchfile, AND return it's output to the variable $output.
      -Eric
        hi andreychek, thanks for your answer. the 'system' command was what i was looking for. if you have time can you state an example where i would use 'exec over system' and not just 'system' all the time? Thank you