2 use vars qw($capture_stderr $VERSION);
8 my ($callpack, $callfile, $callline) = caller;
16 foreach $sym (@EXPORT) {
17 *{"${callpack}::$sym"} = \&{"Shell::$sym"};
27 \$Shell::capture_stderr ? `$cmd 2>&1` : `$cmd`;
29 elsif ('$^O' eq 'os2') {
30 local(\*SAVEOUT, \*READ, \*WRITE);
32 open SAVEOUT, '>&STDOUT' or die;
33 pipe READ, WRITE or die;
34 open STDOUT, '>&WRITE' or die;
37 my \$pid = system(1, '$cmd', \@_);
38 die "Can't execute $cmd: \$!\\n" if \$pid < 0;
40 open STDOUT, '>&SAVEOUT' or die;
60 if ('$^O' eq 'MSWin32') {
61 # XXX this special-casing should not be needed
62 # if we do quoting right on Windows. :-(
64 # First, escape all quotes. Cover the case where we
65 # want to pass along a quote preceded by a backslash
66 # (i.e., C<"param \\""" end">).
67 # Ugly, yup? You know, windoze.
68 # Enclose in quotes only the parameters that need it:
69 # try this: c:\> dir "/w"
70 # and this: c:\> dir /w
73 s/\\\\\\\\"/\\\\\\\\"""/g;
74 \$_ = qq["\$_"] if /\s/;
79 s/(['\\\\])/\\\\\$1/g;
83 push \@arr, '2>&1' if \$Shell::capture_stderr;
84 open(SUBPROC, join(' ', '$cmd', \@arr, '|'))
85 or die "Can't exec $cmd: \$!\\n";
88 close SUBPROC; # XXX Oughta use a destructor.
110 Shell - run shell commands transparently within perl
118 Date: Thu, 22 Sep 94 16:18:16 -0700
119 Message-Id: <9409222318.AA17072@scalpel.netlabs.com>
120 To: perl5-porters@isu.edu
121 From: Larry Wall <lwall@scalpel.netlabs.com>
122 Subject: a new module I just wrote
124 Here's one that'll whack your mind a little out.
130 $foo = echo("howdy", "<funny>", "world");
133 $passwd = cat("</etc/passwd");
139 cp("/etc/passwd", "/tmp/passwd");
141 That's maybe too gonzo. It actually exports an AUTOLOAD to the current
142 package (and uncovered a bug in Beta 3, by the way). Maybe the usual
145 use Shell qw(echo cat ps cp);
150 If you set $Shell::capture_stderr to 1, the module will attempt to
151 capture the STDERR of the process as well.
153 The module now should work on Win32.
161 Changes by Jenda@Krynicky.cz and Dave Cottle <d.cottle@csc.canterbury.ac.nz>