Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

executing a .bat or .exe from within perl script ??

by Newguy2Perl (Initiate)
on Jul 02, 2001 at 23:55 UTC ( #93302=perlquestion: print w/ replies, xml ) Need Help??
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 ??
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://93302]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-09-01 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls