This lets you write into that handle and have what you write show up on
that command's standard input. For example:
- open(PRINTER, "| lpr -Plp1") || die "cannot fork: $!";
+ open(PRINTER, "| lpr -Plp1") || die "can't run lpr: $!";
print PRINTER "stuff\n";
close(PRINTER) || die "can't close lpr: $!";
command writes to its standard output show up on your handle for reading.
For example:
- open(NET, "netstat -i -n |") || die "cannot fork: $!";
+ open(NET, "netstat -i -n |") || die "can't fun netstat: $!";
while (<NET>) { } # do something with input
close(NET) || die "can't close netstat: $!";
-What happens if you try to open a pipe to or from a non-existent command?
-In most systems, such an C<open> will not return an error. That's
-because in the traditional C<fork>/C<exec> model, running the other
-program happens only in the forked child process, which means that
-the failed C<exec> can't be reflected in the return value of C<open>.
-Only a failed C<fork> shows up there. See
-L<perlfaq8/"Why doesn't open() return an error when a pipe open fails?">
-to see how to cope with this. There's also an explanation in L<perlipc>.
+What happens if you try to open a pipe to or from a non-existent
+command? If possible, Perl will detect the failure and set C<$!> as
+usual. But if the command contains special shell characters, such as
+C<E<gt>> or C<*>, called 'metacharacters', Perl does not execute the
+command directly. Instead, Perl runs the shell, which then tries to
+run the command. This means that it's the shell that gets the error
+indication. In such a case, the C<open> call will only indicate
+failure if Perl can't even run the shell. See L<perlfaq8/"How can I
+capture STDERR from an external command?"> to see how to cope with
+this. There's also an explanation in L<perlipc>.
If you would like to open a bidirectional pipe, the IPC::Open2
library will handle this for you. Check out
By default, the C<flock> call will block until a lock is granted.
A request for a shared lock will be granted as soon as there is no
-exclusive locker. A request for a exclusive lock will be granted as
+exclusive locker. A request for an exclusive lock will be granted as
soon as there is no locker of any kind. Locks are on file descriptors,
not file names. You can't lock a file until you open it, and you can't
hold on to a lock once the file has been closed.
Copyright 1998 Tom Christiansen.
-When included as part of the Standard Version of Perl, or as part of
-its complete documentation whether printed or otherwise, this work may
-be distributed only under the terms of Perl's Artistic License. Any
-distribution of this file or derivatives thereof outside of that
-package require that special arrangements be made with copyright
-holder.
+This documentation is free; you can redistribute it and/or modify it
+under the same terms as Perl itself.
Irrespective of its distribution, all code examples in these files are
hereby placed into the public domain. You are permitted and