Learning Perl on Win32 Systems

Learning Perl on Win32 SystemsSearch this book
Previous: 14.1 Using system and execChapter 14
Process Management
Next: 14.3 Using Processes as Filehandles
 

14.2 Using Backquotes

Another way to launch a process is to put a shell command line between backquotes. This fires off a command and waits for its completion, capturing the standard output as it goes along:

@files = `dir`; # gets dir output

The value of @files is the text from the dir command, so it might look something like:

 Volume in drive D has no label.
 Volume Serial Number is 9C5D-713A
 Directory of D:\ora\eg
05/19/97  11:54p        <DIR>          .
05/19/97  11:54p        <DIR>          ..
04/12/97  11:12a                    23 bell.pl
04/12/97  10:56a                    73 console.pl

The standard input and standard error of the command within backquotes are inherited from the Perl process.[1] In other words, the value of the backquoted string is normally just the standard output of the commands within the backquotes.

[1] Actually, the situation is a bit more complicated. See the question in Section 8 of the Perl FAQ on "How can I capture STDERR from an external command?"


Previous: 14.1 Using system and execLearning Perl on Win32 SystemsNext: 14.3 Using Processes as Filehandles
14.1 Using system and execBook Index14.3 Using Processes as Filehandles