books
Free Books / Computers / Practical mod_perl /

previous page: 10.2.6. Starting a Long-Running External Program
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: 10.2.8. Executing system( ) or exec( ) in the Right Way

10.2.7. Starting a Short-Running External Program




Description

This section is from the "Practical mod_perl" book, by Stas Bekman and Eric Cholet. Also available from Amazon: Practical mod_perl

Sometimes you need to call an external program and you cannot continue before this program completes its run (e.g., if you need it to return some result). In this case, the fork solution doesn't help. There are a few ways to execute such a program. First, you could use system( ):

system "perl -e 'print 5+5'"

You would never call the Perl interperter for doing a simple calculation like this, but for the sake of a simple example it's good enough.

The problem with this approach is that we cannot get the results printed to STDOUT. That's where backticks or qx( ) can help. If you use either:

my $result = `perl -e 'print 5+5'`;

or:

my $result = qx{perl -e 'print 5+5'};

the whole output of the external program will be stored in the $result variable.

Of course, you can use other solutions, such as opening a pipe (|) to the program if you need to submit many arguments. And there are more evolved solutions provided by other Perl modules, such as IPC::Open2 and IPC::Open3, that allow you to open a process for reading, writing, and error handling.

 

Continue to:

  • prev: 10.2.6. Starting a Long-Running External Program
  • Table of Contents
  • next: 10.2.8. Executing system( ) or exec( ) in the Right Way

Books by Stas Bekman:















TOP
previous page: 10.2.6. Starting a Long-Running External Program
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: 10.2.8. Executing system( ) or exec( ) in the Right Way

Topics

  • Animals
  • Architecture
  • Arts
  • Business
  • Computers
  • Crafts
  • Fairy Tales
  • Finance
  • Flora and Plants
  • Cooking
  • Gardening
  • Health and Healing
  • History
  • Home Improvements
  • Languages
  • New Age
  • Novels
  • Real Estate
  • Reference
  • Religion
  • Science
  • Society
  • Sports
  • Travel
  • Outdoors


Search

My Books

Headaches Begone! A Systemic Approach To Healing Your Headaches
Don't Let Your Bike Seat Ruin Your Sex Life Book

Discover

  • Answers FAQ

[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007-2021 StasoSphere.com