5 our($capture_stderr, $VERSION, $AUTOLOAD);
9 sub new
{ bless \
$VERSION, shift } # Nothing better to bless
14 my ($callpack, $callfile, $callline) = caller;
21 foreach my $sym (@EXPORT) {
23 *{"${callpack}::$sym"} = \
&{"Shell::$sym"};
28 shift if ref $_[0] && $_[0]->isa( 'Shell' );
34 \
$Shell::capture_stderr ?
`$cmd 2>&1` : `$cmd`;
35 } elsif ('$^O' eq 'os2') {
36 local(\
*SAVEOUT
, \
*READ
, \
*WRITE
);
38 open SAVEOUT
, '>&STDOUT' or die;
39 pipe READ
, WRITE
or die;
40 open STDOUT
, '>&WRITE' or die;
43 my \
$pid = system(1, '$cmd', \
@_);
44 die "Can't execute $cmd: \$!\\n" if \
$pid < 0;
46 open STDOUT
, '>&SAVEOUT' or die;
64 if ('$^O' eq 'MSWin32') {
65 # XXX this special-casing should not be needed
66 # if we do quoting right on Windows. :-(
68 # First, escape all quotes. Cover the case where we
69 # want to pass along a quote preceded by a backslash
70 # (i.e., C<"param \\""" end">).
71 # Ugly, yup? You know, windoze.
72 # Enclose in quotes only the parameters that need it:
73 # try this: c:\> dir "/w"
74 # and this: c:\> dir /w
77 s/\\\\\\\\"/\\\\\\\\"""/g;
78 \
$_ = qq["\$_"] if /\\s/;
82 s/(['\\\\])/\\\\\$1/g;
86 push \
@arr, '2>&1' if \
$Shell::capture_stderr
;
87 open(SUBPROC
, join(' ', '$cmd', \
@arr, '|'))
88 or die "Can't exec $cmd: \$!\\n";
91 close SUBPROC
; # XXX Oughta use a destructor.
113 Shell - run shell commands transparently within perl
121 Date: Thu, 22 Sep 94 16:18:16 -0700
122 Message-Id: <9409222318.AA17072@scalpel.netlabs.com>
123 To: perl5-porters@isu.edu
124 From: Larry Wall <lwall@scalpel.netlabs.com>
125 Subject: a new module I just wrote
127 Here's one that'll whack your mind a little out.
133 $foo = echo("howdy", "<funny>", "world");
136 $passwd = cat("</etc/passwd");
142 cp("/etc/passwd", "/tmp/passwd");
144 That's maybe too gonzo. It actually exports an AUTOLOAD to the current
145 package (and uncovered a bug in Beta 3, by the way). Maybe the usual
148 use Shell qw(echo cat ps cp);
153 If you set $Shell::capture_stderr to 1, the module will attempt to
154 capture the STDERR of the process as well.
156 The module now should work on Win32.
160 There seemed to be a problem where all arguments to a shell command were
161 quoted before being executed. As in the following example:
176 and of course, this is wrong.
178 I have fixed this bug, it was brought up by Wolfgang Laun [ID 20000326.008]
182 =head2 OBJECT ORIENTED SYNTAX
184 Shell now has an OO interface. Good for namespace conservation
185 and shell representation.
197 Changes by Jenda@Krynicky.cz and Dave Cottle <d.cottle@csc.canterbury.ac.nz>
199 Changes and bug fixes by Casey Tweten <crt@kiski.net>