summaryrefslogtreecommitdiff
path: root/lib/open3.pl
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-12-20 11:14:00 +1200
committerChip Salzenberg <chip@atlantic.net>1996-12-20 11:14:00 +1200
commit7e1af8bca57f405a8444b575a870918a6d88fc5c (patch)
treeb443adc34d8d77831bf947076abd5770335592cf /lib/open3.pl
parent7f3dfc00eaef7e421633b2b47af9963dbc626e75 (diff)
downloadperl-7e1af8bca57f405a8444b575a870918a6d88fc5c.tar.gz
[inseparable changes from patch from perl5.003_12 to perl5.003_13]
DOCUMENTATION Subject: small doc tweaks for _12 Date: Thu, 19 Dec 1996 11:05:57 -0500 From: Roderick Schertler <roderick@gate.net> Files: lib/UNIVERSAL.pm pod/perldiag.pod pod/perltie.pod Msg-ID: <1826.851011557@eeyore.ibcinc.com> (applied based on p5p patch as commit 3314ffc68a11690bd9977cbdd7ea0601ad6ced13) PORTABILITY Subject: Add missing backslash in Configure From: Chip Salzenberg <chip@atlantic.net> Files: Configure UTILITIES, LIBRARY, AND EXTENSIONS Subject: Include libnet-1.01 instead of old Net::FTP From: Graham Barr <Graham.Barr@tiuk.ti.com> Files: MANIFEST lib/Net/Cmd.pm lib/Net/Domain.pm lib/Net/DummyInetd.pm lib/Net/FTP.pm lib/Net/NNTP.pm lib/Net/Netrc.pm lib/Net/POP3.pm lib/Net/SMTP.pm lib/Net/SNPP.pm lib/Net/Socket.pm lib/Net/Telnet.pm lib/Net/Time.pm pod/perlmod.pod Subject: Use binmode when doing binary FTP From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: lib/Net/FTP.pm Subject: Re: Open3.pm tries to close unopened file handle Date: 18 Dec 1996 22:19:54 -0500 From: Roderick Schertler <roderick@gate.net> Files: MANIFEST lib/IPC/Open2.pm lib/IPC/Open3.pm lib/open2.pl lib/open3.pl pod/perldiag.pod pod/perlfunc.pod t/lib/open2.t t/lib/open3.t Msg-ID: <pzloavmd9h.fsf@eeyore.ibcinc.com> (applied based on p5p patch as commit 982b4e8fc47473059e209787b589853f4c8f8f9e) Subject: Long-standing problem in Socket module Date: Wed, 18 Dec 1996 23:18:14 -0500 From: Spider Boardman <spider@orb.nashua.nh.us> Files: Configure Porting/Glossary config_H config_h.SH ext/Socket/Socket.pm ext/Socket/Socket.xs Msg-ID: <199612190418.XAA07291@Orb.Nashua.NH.US> (applied based on p5p patch as commit 3e6a22d2723daf415793f9a4fc1b57f4d8a576fd) Subject: flock() constants Date: Thu, 19 Dec 1996 01:37:17 -0500 From: Roderick Schertler <roderick@gate.net> Files: ext/Fcntl/Fcntl.pm ext/Fcntl/Fcntl.xs pod/perlfunc.pod Msg-ID: <26669.850977437@eeyore.ibcinc.com> (applied based on p5p patch as commit 3dea0e15e4684f6defe2f25a16bc696b96697ac2)
Diffstat (limited to 'lib/open3.pl')
-rw-r--r--lib/open3.pl110
1 files changed, 8 insertions, 102 deletions
diff --git a/lib/open3.pl b/lib/open3.pl
index 8b3917a851..7fcc931861 100644
--- a/lib/open3.pl
+++ b/lib/open3.pl
@@ -1,106 +1,12 @@
-# &open3: Marc Horowitz <marc@mit.edu>
-# derived mostly from &open2 by tom christiansen, <tchrist@convex.com>
+# This is a compatibility interface to IPC::Open3. New programs should
+# do
#
-# $Id: open3.pl,v 1.1 1993/11/23 06:26:15 marc Exp $
+# use IPC::Open3;
#
-# usage: $pid = open3('wtr', 'rdr', 'err' 'some cmd and args', 'optarg', ...);
+# instead of
#
-# spawn the given $cmd and connect rdr for
-# reading, wtr for writing, and err for errors.
-# if err is '', or the same as rdr, then stdout and
-# stderr of the child are on the same fh. returns pid
-# of child, or 0 on failure.
+# require 'open3.pl';
-
-# if wtr begins with '>&', then wtr will be closed in the parent, and
-# the child will read from it directly. if rdr or err begins with
-# '>&', then the child will send output directly to that fd. In both
-# cases, there will be a dup() instead of a pipe() made.
-
-
-# WARNING: this is dangerous, as you may block forever
-# unless you are very careful.
-#
-# $wtr is left unbuffered.
-#
-# abort program if
-# rdr or wtr are null
-# pipe or fork or exec fails
-
-package open3;
-
-$fh = 'FHOPEN000'; # package static in case called more than once
-
-sub main'open3 {
- local($kidpid);
- local($dad_wtr, $dad_rdr, $dad_err, @cmd) = @_;
- local($dup_wtr, $dup_rdr, $dup_err);
-
- $dad_wtr || die "open3: wtr should not be null";
- $dad_rdr || die "open3: rdr should not be null";
- $dad_err = $dad_rdr if ($dad_err eq '');
-
- $dup_wtr = ($dad_wtr =~ s/^\>\&//);
- $dup_rdr = ($dad_rdr =~ s/^\>\&//);
- $dup_err = ($dad_err =~ s/^\>\&//);
-
- # force unqualified filehandles into callers' package
- local($package) = caller;
- $dad_wtr =~ s/^([^']+$)/$package'$1/;
- $dad_rdr =~ s/^([^']+$)/$package'$1/;
- $dad_err =~ s/^([^']+$)/$package'$1/;
-
- local($kid_rdr) = ++$fh;
- local($kid_wtr) = ++$fh;
- local($kid_err) = ++$fh;
-
- if (!$dup_wtr) {
- pipe($kid_rdr, $dad_wtr) || die "open3: pipe 1 (stdin) failed: $!";
- }
- if (!$dup_rdr) {
- pipe($dad_rdr, $kid_wtr) || die "open3: pipe 2 (stdout) failed: $!";
- }
- if ($dad_err ne $dad_rdr && !$dup_err) {
- pipe($dad_err, $kid_err) || die "open3: pipe 3 (stderr) failed: $!";
- }
-
- if (($kidpid = fork) < 0) {
- die "open2: fork failed: $!";
- } elsif ($kidpid == 0) {
- if ($dup_wtr) {
- open(STDIN, "<&$dad_wtr") if (fileno(STDIN) != fileno($dad_wtr));
- } else {
- close($dad_wtr);
- open(STDIN, "<&$kid_rdr");
- }
- if ($dup_rdr) {
- open(STDOUT, ">&$dad_rdr") if (fileno(STDOUT) != fileno($dad_rdr));
- } else {
- close($dad_rdr);
- open(STDOUT, ">&$kid_wtr");
- }
- if ($dad_rdr ne $dad_err) {
- if ($dup_err) {
- open(STDERR, ">&$dad_err")
- if (fileno(STDERR) != fileno($dad_err));
- } else {
- close($dad_err);
- open(STDERR, ">&$kid_err");
- }
- } else {
- open(STDERR, ">&STDOUT") if (fileno(STDERR) != fileno(STDOUT));
- }
- local($")=(" ");
- exec @cmd;
- die "open2: exec of @cmd failed";
- }
-
- close $kid_rdr; close $kid_wtr; close $kid_err;
- if ($dup_wtr) {
- close($dad_wtr);
- }
-
- select((select($dad_wtr), $| = 1)[0]); # unbuffer pipe
- $kidpid;
-}
-1; # so require is happy
+package main;
+use IPC::Open3 'open3';
+1