Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Run other processes from within your Perl program

There are several ways in Perl that you can run another process from within your Perl program:

1. You can use a system call, which runs the other process independently and returns to you when it has completed. You can check the completion status of the system call by examining $?. Before it runs, system flushes all Perl files open for output before it runs the process. (from 5.6.0)

Example:
  system("ls");


2. You can run a command in backtics (or using qx). In this case, the command runs to completion and the results are then returned to you as a string.

Example:
  $results = `ls`;

3. You can open a command (process) on a file handle, using a pipe character | as the "direction" character. And you can then read from, or write to, that file handle to pick up results as the command runs.

Example:
  open (FH,"ls|");
  while (<FH>) {
    print ;
    }


In the first two cases, the command runs to completion before your Perl program carries on; in the third case, the command is running in parallel to your Perl program and you can read from before it is completed - that's very useful for handling something like a monitoring program which you want to interactively summarise / report on.

There are examples of all three syntaxes [here] - written as a demonstration during last week's Perl Programming Course.
(written 2012-12-03, updated 2012-12-08)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P223 - Perl - Interprocess Communication
  [604] Perl - multiprocess applications - (2006-02-13)
  [1918] Perl Socket Programming Examples - (2008-12-02)
  [2694] Multiple processes (forking) in Python - (2010-03-25)
  [2970] Perl - doing several things at the same time - (2010-09-25)
  [3010] Children, zombies, and reaping processes - (2010-10-23)
  [3011] What are .pid files? - (2010-10-23)
  [3412] Handling binary data in Perl is easy! - (2011-08-30)


Back to
Lots of ways of doing the same thing in Perl - list iteration
Previous and next
or
Horse's mouth home
Forward to
Building an object based on another object in Perl
Some other Articles
Melksham Christmas Lights, 2012
With us for a year already!
Santa Trip - Melksham Railway Development Group, 2012
Building an object based on another object in Perl
Run other processes from within your Perl program
Lots of ways of doing the same thing in Perl - list iteration
A long overdue meeting - a steeping stone towards coordinate transport user inputs
Agenda for Wiltshire Link Travel groups meeting, Saturday 1st December 2012
Lisa is home today ...
Whether you have programmed before or not, we can teach you Python
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3940_Run ... ogram.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb