O'Reilly logo

Learning Perl, Second Edition by Randal L. Schwartz, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.5. Summary of Process Operations

Table 14.1 summarizes the operations that you have for launching a process.

Table 14.1. Summary of Subprocess Operations
OperationStandard InputStandard OutputStandard ErrorWaited for?
system()
Inherited from programInherited from programInherited from programYes
Backquoted stringInherited from programCaptured as string valueInherited from programYes
open() command as filehandle for outputConnected to filehandleInherited from programInherited from programOnly at time of close()
open() command as filehandle for inputInherited from programConnected to filehandleInherited from programOnly at time of close()
fork, exec, wait, waitpidUser selectedUser selectedUser selectedUser selected

The simplest way to create a process is with the system function. Standard input, output, and error are unaffected (they're inherited from the Perl process). A backquoted string creates a process, capturing the standard output of the process as a string value for the Perl program. Standard input and standard error are unaffected. Both these methods require that the process finish before any more code is executed.

A simple way to get an asynchronous process (one that allows the Perl program to continue before the process is complete) is to open a command as a filehandle, creating a pipe for the command's standard input or standard output. A command opened as a filehandle for reading inherits the standard input and standard error from the Perl program; a command opened as ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required