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' );
33 shift if ref \$_[0] && \$_[0]->isa( 'Shell' );
35 \$Shell::capture_stderr ? `$cmd 2>&1` : `$cmd`;
36 } elsif ('$^O' eq 'os2') {
37 local(\*SAVEOUT, \*READ, \*WRITE);
39 open SAVEOUT, '>&STDOUT' or die;
40 pipe READ, WRITE or die;
41 open STDOUT, '>&WRITE' or die;
44 my \$pid = system(1, '$cmd', \@_);
45 die "Can't execute $cmd: \$!\\n" if \$pid < 0;
47 open STDOUT, '>&SAVEOUT' or die;
65 if ('$^O' eq 'MSWin32') {
66 # XXX this special-casing should not be needed
67 # if we do quoting right on Windows. :-(
69 # First, escape all quotes. Cover the case where we
70 # want to pass along a quote preceded by a backslash
71 # (i.e., C<"param \\""" end">).
72 # Ugly, yup? You know, windoze.
73 # Enclose in quotes only the parameters that need it:
74 # try this: c:\> dir "/w"
75 # and this: c:\> dir /w
78 s/\\\\\\\\"/\\\\\\\\"""/g;
79 \$_ = qq["\$_"] if /\\s/;
83 s/(['\\\\])/\\\\\$1/g;
87 push \@arr, '2>&1' if \$Shell::capture_stderr;
88 open(SUBPROC, join(' ', '$cmd', \@arr, '|'))
89 or die "Can't exec $cmd: \$!\\n";
92 close SUBPROC; # XXX Oughta use a destructor.
114 Shell - run shell commands transparently within perl
122 Date: Thu, 22 Sep 94 16:18:16 -0700
123 Message-Id: <9409222318.AA17072@scalpel.netlabs.com>
124 To: perl5-porters@isu.edu
125 From: Larry Wall <lwall@scalpel.netlabs.com>
126 Subject: a new module I just wrote
128 Here's one that'll whack your mind a little out.
134 $foo = echo("howdy", "<funny>", "world");
137 $passwd = cat("</etc/passwd");
143 cp("/etc/passwd", "/tmp/passwd");
145 That's maybe too gonzo. It actually exports an AUTOLOAD to the current
146 package (and uncovered a bug in Beta 3, by the way). Maybe the usual
149 use Shell qw(echo cat ps cp);
154 If you set $Shell::capture_stderr to 1, the module will attempt to
155 capture the STDERR of the process as well.
157 The module now should work on Win32.
161 There seemed to be a problem where all arguments to a shell command were
162 quoted before being executed. As in the following example:
177 and of course, this is wrong.
179 I have fixed this bug, it was brought up by Wolfgang Laun [ID 20000326.008]
183 =head2 OBJECT ORIENTED SYNTAX
185 Shell now has an OO interface. Good for namespace conservation
186 and shell representation.
198 Changes by Jenda@Krynicky.cz and Dave Cottle <d.cottle@csc.canterbury.ac.nz>
200 Changes and bug fixes by Casey West <casey@geeknest.com>