[30832] in Perl-Users-Digest
Perl-Users Digest, Issue: 2077 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 25 14:09:48 2008
Date: Thu, 25 Dec 2008 11:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 25 Dec 2008 Volume: 11 Number: 2077
Today's topics:
Re: Buffering problem with 'open' - ideas ? <jurgenex@hotmail.com>
Re: Buffering problem with 'open' - ideas ? <asuter@cisco.com>
Re: Buffering problem with 'open' - ideas ? <asuter@cisco.com>
Re: FAQ 4.2 Why is int() broken? <hjp-usenet2@hjp.at>
Re: Mathematica 7 compares to other languages <xahlee@gmail.com>
new CPAN modules on Thu Dec 25 2008 (Randal Schwartz)
Re: Non-OO interface to mysql <hjp-usenet2@hjp.at>
Re: Press a button <pod69@gmx.net>
Re: Press a button <tim@burlyhost.com>
Re: Understanding tempfile and open3 usenet@schweikhardt.net
Re: Understanding tempfile and open3 sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Dec 2008 08:39:57 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Buffering problem with 'open' - ideas ?
Message-Id: <jpd7l4hkd8ugiucvoknl3750g1hhqn06rk@4ax.com>
"Asim Suter" <asuter@cisco.com> wrote:
>I need to run a command in interactive fashion as well as catch its output.
Are you trying to reinvent the Expect module?
jue
------------------------------
Date: Thu, 25 Dec 2008 09:58:06 -0800
From: "Asim Suter" <asuter@cisco.com>
Subject: Re: Buffering problem with 'open' - ideas ?
Message-Id: <1230227887.629381@sj-nntpcache-2.cisco.com>
"John W. Krahn" <someone@example.com> wrote in message
news:egD4l.8035$lX6.5562@newsfe06.iad...
> Asim Suter wrote:
>>
>> I need to run a command in interactive fashion as well as catch its
>> output.
>> So I wrote following: along with imagined line #s so that its easy to
>> reference.
>>
>> 1
>> 2 my $c = "some Unix command that prompts for yes/no";
>> 3
>> 4 unless (open(FH, "$c 2>&1 |"))
>> 5 {
>> 6 die "Can't spawn external command $c!";
>> 7 }
>> 8
>> 9 while (defined (my $line = <FH>))
>> 10 {
>> 11 print_console_and_log $line;
>> 12 }
>> 13 unless (close(FH))
>> 14 {
>> 15 die "External command failed $c: $?";
>> 16 }
>> 17
>>
>> What I observe is:
>> Apparently an hanging shell - which on hitting "Enter" on the shell
>> prints
>> "Are you sure you want to do this?" which is being outputted by the
>> command in $c.
>>
>> So it appears to me a buffering problem:
>>
>> In the hope of removing buffering, I tried a couple of things
>>
>> Soln_A:
>>
>> $| = 1;
>>
>> Soln_B:
>>
>> use IO::Handle;
>> FH->autoflush(1); #after line 7
>>
>> Soln_C
>>
>> select((select(FH),$|=1)[0]); #after line 7
>>
>> None of them seem to give me what I want - which is get rid of buffering
>> and thus outputting
>> "Are you sure you want to do this?" so that user can proceed and not get
>> the feeling of the shell hanging.
>>
>> Any other tricks you might suggest or any other insights ?
>
> It sounds like you need to use the Expect module:
>
> http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod
>
>
>
> John
Expect is useful when its needed to 'feed' input to program in an automated
fashion.
That's not my intent. I still need the operation be human controlled on the
shell. The human
may choose yes or no.
Thanks but any other ideas ?
Asim
------------------------------
Date: Thu, 25 Dec 2008 09:58:42 -0800
From: "Asim Suter" <asuter@cisco.com>
Subject: Re: Buffering problem with 'open' - ideas ?
Message-Id: <1230227923.419372@sj-nntpcache-2.cisco.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:jpd7l4hkd8ugiucvoknl3750g1hhqn06rk@4ax.com...
> "Asim Suter" <asuter@cisco.com> wrote:
>>I need to run a command in interactive fashion as well as catch its
>>output.
>
> Are you trying to reinvent the Expect module?
>
> jue
Expect is useful when its needed to 'feed' input to program in an automated
fashion.
That's not my intent. I still need the operation be human controlled on the
shell. The human
may choose yes or no.
Thanks but any other ideas ?
Asim
------------------------------
Date: Thu, 25 Dec 2008 10:57:44 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 4.2 Why is int() broken?
Message-Id: <slrngl6m8p.sfq.hjp-usenet2@hrunkner.hjp.at>
On 2008-12-23 20:03, PerlFAQ Server <brian@stonehenge.com> wrote:
> --------------------------------------------------------------------
>
> 4.2: Why is int() broken?
>
> Your "int()" is most probably working just fine. It's the numbers that
> aren't quite what you think.
>
> First, see the answer to "Why am I getting long decimals (eg,
> 19.9499999999999) instead of the numbers I should be getting (eg,
> 19.95)?".
>
> For example, this
>
> print int(0.6/0.2-2), "\n";
print int(0.6/0.2), "\n";
>
> will in most computers print 0, not 1, because even such simple numbers
will in most computers print 2, not 3, because even such simple numbers
(The extra subtraction is not necessary to demonstrate the problem and is
distracting)
> as 0.6 and 0.2 cannot be presented exactly by floating-point numbers.
as 0.6 and 0.2 cannot be represented exactly by binary floating-point numbers.
(0.6 and 0.2 can be represented exactly in decimal floating-point
numbers. Or in base 5 or base 100, or any other base which is a multiple
of 5. The problem isn't floating-point, it's binary. A binary fixed
point representation would have the same problem.)
> What you think in the above as 'three' is really more like
> 2.9999999999999995559.
------------------------------
Date: Thu, 25 Dec 2008 03:24:31 -0800 (PST)
From: Xah Lee <xahlee@gmail.com>
Subject: Re: Mathematica 7 compares to other languages
Message-Id: <a917ba86-8f89-4419-b491-5e17fd80b569@z6g2000pre.googlegroups.com>
> >On Dec 10, 2:47 pm, John W Kennedy <jwke...@attglobal.net> wrote:
> >> C:
>
> >> #include <stdlib.h>
> >> #include <math.h>
>
> >> void normal(int dim, float* x, float* a) {
> >> float sum =3D 0.0f;
> >> int i;
> >> float divisor;
> >> for (i =3D 0; i < dim; ++i) sum +=3D x[i] * x[i];
> >> divisor =3D sqrt(sum);
> >> for (i =3D 0; i < dim; ++i) a[i] =3D x[i]/divisor;
>
> >> }
Due to the low level of C, this C example should perhaps then accept a
sequence of numbers separated by space, and print the output. Having
dimension as part of input is not acceptable.
For examples in other langs that can take any input (in source code)
and print output, see:
http://xahlee.org/UnixResource_dir/writ/Mathematica_expressiveness.html
A new addition is in Scheme Lisp:
;; Scheme Lisp. By Bakul Shah
(define (normalize vec)
(let ((d (sqrt (apply + (map (lambda (x) (* x x)) vec)))))
(map (lambda (x) (/ x d)) vec)))
(normalize '(3 4))
The JavaScript example:
// Javascript. By William James
function normalize( vec ) {
var div=3DMath.sqrt(vec.map(function(x) x*x).reduce(function(a,b) a+b))
return vec.map(function(x) x/div)
}
is also not qualified. (it is syntax error in SpiderMonkey engine
=E2=80=9CJavaScript-C 1.7.0 2007-10-03=E2=80=9D)
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
------------------------------
Date: Thu, 25 Dec 2008 05:42:24 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Dec 25 2008
Message-Id: <KCF3uo.DLn@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
App-Cmd-Plugin-Prompt-1.000
http://search.cpan.org/~rjbs/App-Cmd-Plugin-Prompt-1.000/
plug prompting routines into your commands
----
App-PPBuild-0.08
http://search.cpan.org/~exodist/App-PPBuild-0.08/
Perl Project Build System, The low-learning curve simple build system.
----
App-PPBuild-0.09
http://search.cpan.org/~exodist/App-PPBuild-0.09/
Perl Project Build System, The low-learning curve simple build system.
----
BioPerl-1.5.9_001
http://search.cpan.org/~cjfields/BioPerl-1.5.9_001/
Loader for LiveSeq from EMBL entries with BioPerl
----
BioPerl-1.5.9_1
http://search.cpan.org/~cjfields/BioPerl-1.5.9_1/
Loader for LiveSeq from EMBL entries with BioPerl
----
Business-DateTime-0.0.2
http://search.cpan.org/~stocks/Business-DateTime-0.0.2/
----
Business-TNTPost-NL-0.06
http://search.cpan.org/~blom/Business-TNTPost-NL-0.06/
Calculate Dutch (TNT Post) shipping costs
----
Class-C3-Adopt-NEXT-0.06
http://search.cpan.org/~flora/Class-C3-Adopt-NEXT-0.06/
make NEXT suck less
----
Devel-StackTrace-WithLexicals-0.03
http://search.cpan.org/~sartak/Devel-StackTrace-WithLexicals-0.03/
Devel::StackTrace + PadWalker
----
EV-3.51
http://search.cpan.org/~mlehmann/EV-3.51/
perl interface to libev, a high performance full-featured event loop
----
Fey-ORM-0.17
http://search.cpan.org/~drolsky/Fey-ORM-0.17/
A Fey-based ORM
----
Fey-ORM-0.18
http://search.cpan.org/~drolsky/Fey-ORM-0.18/
A Fey-based ORM
----
KiokuDB-Backend-DBI-0.04
http://search.cpan.org/~nuffin/KiokuDB-Backend-DBI-0.04/
DBI backend for KiokuDB
----
Mac-Finder-DSStore-0.92
http://search.cpan.org/~wiml/Mac-Finder-DSStore-0.92/
Read and write Macintosh Finder DS_Store files
----
Markapl-0.07
http://search.cpan.org/~gugod/Markapl-0.07/
Markup as Perl
----
Net-OpenSSH-0.11
http://search.cpan.org/~salva/Net-OpenSSH-0.11/
Perl SSH client package implemented on top of OpenSSH
----
POE-API-Hooks-1.07
http://search.cpan.org/~sungo/POE-API-Hooks-1.07/
Implement lightweight hooks into POE
----
POE-Component-DebugShell-1.412
http://search.cpan.org/~sungo/POE-Component-DebugShell-1.412/
Component to allow interactive peeking into a running POE application
----
Padre-Plugin-Perl6-0.013
http://search.cpan.org/~azawawi/Padre-Plugin-Perl6-0.013/
Padre plugin for Perl6
----
Parse-ErrorString-Perl-0.07
http://search.cpan.org/~pshangov/Parse-ErrorString-Perl-0.07/
Parse error messages from the perl interpreter
----
Search-Xapian-1.0.10.0
http://search.cpan.org/~olly/Search-Xapian-1.0.10.0/
Perl XS frontend to the Xapian C++ search library.
----
Simo-0.02
http://search.cpan.org/~kimoto/Simo-0.02/
Very simple framework for Object Oriented Perl.
----
String-CaseProfile-0.13
http://search.cpan.org/~enell/String-CaseProfile-0.13/
Get/Set the letter case profile of a string
----
Term-Highlight-1.5
http://search.cpan.org/~radkov/Term-Highlight-1.5/
perl module to highlight regexp patterns on terminals
----
Test-DBUnit-0.17
http://search.cpan.org/~adrianwit/Test-DBUnit-0.17/
Database testing framework.
----
WeakRef-Auto-0.01
http://search.cpan.org/~gfuji/WeakRef-Auto-0.01/
Automatically makes references weaken
----
Wiki-Toolkit-0.77
http://search.cpan.org/~dom/Wiki-Toolkit-0.77/
A toolkit for building Wikis.
----
XML-Bare-0.40
http://search.cpan.org/~codechild/XML-Bare-0.40/
Minimal XML parser implemented via a C state engine
----
mobirc-1.99_01
http://search.cpan.org/~tokuhirom/mobirc-1.99_01/
modern IRC to HTTP gateway
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Thu, 25 Dec 2008 10:43:10 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Non-OO interface to mysql
Message-Id: <slrngl6ldf.km8.hjp-usenet2@hrunkner.hjp.at>
On 2008-12-23 13:16, C.DeRykus <ced@blv-sam-01.ca.boeing.com> wrote:
> On Dec 23, 3:11 am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
>> On 2008-12-23 05:28, C.DeRykus <c...@blv-sam-01.ca.boeing.com> wrote:
>> > On Dec 22, 4:04 am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
>> >> If you repeat that a few times you will see that in about 50 % of the
>> >> cases the procedural call is slightly faster than the oo call and in
>> >> 50 % of the cases the oo call is slightly faster - or in other words,
>> >> the difference is not even measurable with a simple benchmark.
>>
>> > Totally agree but this particular code gives OO an
>> > edge due to method caching.
>>
>> > A slight tweak: $arg . ("a".."z")[int(rand(26))]
>> > consistently tilts for the faster procedural call ...
>> > at least for some small Solaris and Linux sample
>> > runs.
>>
>> Interesting. I hadn't expected that the values of the arguments have an
>> influence on the method cache. How does the method cache work?
>
> Actually, I just assumed that expensive method pointer
> lookups were being cached and that leveled the playing
> field. Normally, that extra lookup would slow the OO
> call and procedural would win.
Well, the purpose of my test code was to find out how expensive these
pointer lookups really are. A single pointer lookup would be completely
insignificant compared to a normal perl subroutine call (which is
already quite expensive). A hash lookup would be more expensive. If @ISA
had to be searched (recursively) for each call, it would be even more
expensive. My simple benchmark indicated that the overhead was very low
(about 15ns per call), so I assumed it was only an extra pointer lookup
or so. Your modification dramatically increased the overhead of the oo
code (to about 285 ns per call). So my assumption was obviously wrong.
What irritates me is that I don't see what could cause the difference.
> Also, I assume that if the method argument is constant, as it is
> here, the call result itself could be cached too
No, this is not possible. Consider the call «rand(26)» in your code
(rand is a builtin, but it could easily be implemented in Perl): The
argument is a constant (26), but the return value changes every time.
If perl would cache the return value the result wouldn't be very random,
would it?
> and that'd apply to the procedural call too.
Right.
In both the oo and the procedural case the compiler could determine that
a function is "pure" (i.e., the result depends only on the arguments)
and optimize accordingly. Perl doesn't afaik, with one important
exception: A function with prototype () returning a constant is inlined.
There is a module "Memoize" to add a caching layer to any sub.
hp
------------------------------
Date: Thu, 25 Dec 2008 19:46:25 +0100
From: pod <pod69@gmx.net>
Subject: Re: Press a button
Message-Id: <4953d504$0$2633$91cee783@newsreader01.highway.telekom.at>
Hello
Thx for your answer - I use use the below code but I get a HTTP/1.0 403
Forbidden. Any idea?
use HTTP::Headers;
use HTTP::Request;
use LWP::UserAgent;
use LWP::ConnCache;
use strict;
my $url =
'http://10.0.0.138/cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET';
my $content = '0=13&1=INTERNET&2=3342349270&5=2';
my $method = 'POST';
my
$referer='http://10.0.0.138/cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET';
my $header = HTTP::Headers->new (
'ACCEPT'=>'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'ACCEPT_LANGUAGE'=>'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3',
'REFERER'=>"$referer",
'USER_AGENT'=>'Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)');
my $ua = LWP::UserAgent->new;
$ua->conn_cache(LWP::ConnCache->new());
my $request = HTTP::Request->new ($method, $url, $header, $content);
$request->content_type('application/x-www-form-urlencoded');
my $response = $ua->request($request);
print $response->content;
POST /cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET HTTP/1.1
TE: deflate,gzip;q=0.3
Keep-Alive: 300
Connection: Keep-Alive, TE
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Host: 10.0.0.138
Referer: http://10.0.0.138/cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
0=13&1=INTERNET&2=3342349270&5=2HTTP/1.0 403 Forbidden
Server: Speed Touch WebServer/1.0
Content-Type: text/html
Content-Length: 24
HTTP/1.0 403 Forbidden
thx
------------------------------
Date: Thu, 25 Dec 2008 11:05:00 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Press a button
Message-Id: <xPQ4l.10147$lX6.9566@newsfe06.iad>
pod wrote:
> Hello
>
> Thx for your answer - I use use the below code but I get a HTTP/1.0
> 403 Forbidden. Any idea?
Does that web interface require a login/active session to run the
commands you pass to it (posting to that URL)?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Thu, 25 Dec 2008 07:06:10 -0800 (PST)
From: usenet@schweikhardt.net
Subject: Re: Understanding tempfile and open3
Message-Id: <477700ad-694f-4e9e-9c81-fa0557fa7366@40g2000prx.googlegroups.com>
On Dec 25, 3:34=A0am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "u" =3D=3D usenet =A0<use...@schweikhardt.net> writes:
>
> =A0 u> use File::Temp qw(tempfile);
> =A0 u> use IPC::Open3;
>
> =A0 u> # A command producing output on both stdout and stderr.
> =A0 u> my @cmd =3D ('gcc', '-E', '-v', '-dM', '-x', 'c', '/dev/null');
>
> =A0 u> # Temp file where @cmd's stdout should go.
> =A0 u> my ($filehandle, $filename) =3D tempfile ('predef-XXXXXX', DIR =3D=
> ".",
> =A0 u> =A0 SUFFIX =3D> '.h', UNLINK =3D> 0);
>
> =A0 u> # What I want: write stdout to $filehandle and end up in $filename=
;
> =A0 u> # =A0 =A0 =A0 =A0 =A0 =A0 =A0read stderr from <ERR>.
> =A0 u> my $pid =3D open3 (gensym, $filehandle, \*ERR, @cmd);
>
> your problem is in that line. open3 doesn't connect a process to file
> handles that are open with files. it is meant to give you an open handle
> to talk to the subprocess. once open3 is called you have to do all the
> i/o afterwards - all it does is fork/exec the command while attaching
> the handles (which are not pre-opened to anything) to the stdio/err of
> the process.
Thanks Uri, for pointing me to this. In fact, open3 has a way
to use an existing file handle when it is prefixed with ">&".
This works as expected:
#!/usr/local/bin/perl -w
use strict;
use File::Temp qw(tempfile);
use IPC::Open3;
use Symbol qw(gensym);
# A command producing output on both stdout and stderr.
my @cmd =3D ('gcc', '-E', '-v', '-dM', '-x', 'c', '/dev/null');
# Temp file where @cmd's stdout should go.
my ($filehandle, $filename) =3D tempfile ('predef-XXXXXX', DIR =3D> ".",
SUFFIX =3D> '.h', UNLINK =3D> 0);
# What I want: write stdout to $filehandle and end up in $filename;
# read stderr from <ERR>.
open FH, ">$filename" or die "$!";
my $pid =3D open3 (gensym, ">&FH", \*ERR, @cmd);
while (<ERR>) {
print $_ if /^\s\S+$/; # This works fine.
# Do more things with $_.
}
waitpid ($pid, 0) or die "$!";
close FH;
system ('wc', $filename);
Now the only ugly part here is that I seem unable to
use $filehandle directly with open3 and ">&". Instead
I go the detour via open FH, ">$filename". Hasn't
tempfile() done something very similar (given me a
handle and name)? Is there a way to make open3 accept
some combination of ">&" and $filehandle without the
FH detour? (I want tempfile for its race avoidance and
autoremoval of temp file features).
Thanks and merry Christmas!
Jens
------------------------------
Date: Thu, 25 Dec 2008 17:35:28 GMT
From: sln@netherlands.com
Subject: Re: Understanding tempfile and open3
Message-Id: <uog7l49lbigto682od27feleavcstmuv2l@4ax.com>
On Thu, 25 Dec 2008 07:06:10 -0800 (PST), usenet@schweikhardt.net wrote:
>On Dec 25, 3:34 am, Uri Guttman <u...@stemsystems.com> wrote:
>> >>>>> "u" == usenet <use...@schweikhardt.net> writes:
>>
>> u> use File::Temp qw(tempfile);
>> u> use IPC::Open3;
>>
>> u> # A command producing output on both stdout and stderr.
>> u> my @cmd = ('gcc', '-E', '-v', '-dM', '-x', 'c', '/dev/null');
>>
>> u> # Temp file where @cmd's stdout should go.
>> u> my ($filehandle, $filename) = tempfile ('predef-XXXXXX', DIR => ".",
>> u> SUFFIX => '.h', UNLINK => 0);
>>
>> u> # What I want: write stdout to $filehandle and end up in $filename;
>> u> # read stderr from <ERR>.
>> u> my $pid = open3 (gensym, $filehandle, \*ERR, @cmd);
>>
>> your problem is in that line. open3 doesn't connect a process to file
>> handles that are open with files. it is meant to give you an open handle
>> to talk to the subprocess. once open3 is called you have to do all the
>> i/o afterwards - all it does is fork/exec the command while attaching
>> the handles (which are not pre-opened to anything) to the stdio/err of
>> the process.
>
>Thanks Uri, for pointing me to this. In fact, open3 has a way
>to use an existing file handle when it is prefixed with ">&".
>This works as expected:
>
>#!/usr/local/bin/perl -w
>
>use strict;
>use File::Temp qw(tempfile);
>use IPC::Open3;
>use Symbol qw(gensym);
>
># A command producing output on both stdout and stderr.
>my @cmd = ('gcc', '-E', '-v', '-dM', '-x', 'c', '/dev/null');
>
># Temp file where @cmd's stdout should go.
>my ($filehandle, $filename) = tempfile ('predef-XXXXXX', DIR => ".",
> SUFFIX => '.h', UNLINK => 0);
>
># What I want: write stdout to $filehandle and end up in $filename;
># read stderr from <ERR>.
>open FH, ">$filename" or die "$!";
>my $pid = open3 (gensym, ">&FH", \*ERR, @cmd);
>while (<ERR>) {
> print $_ if /^\s\S+$/; # This works fine.
> # Do more things with $_.
>}
>waitpid ($pid, 0) or die "$!";
>close FH;
>
>system ('wc', $filename);
>
>
>Now the only ugly part here is that I seem unable to
>use $filehandle directly with open3 and ">&". Instead
>I go the detour via open FH, ">$filename". Hasn't
>tempfile() done something very similar (given me a
>handle and name)? Is there a way to make open3 accept
>some combination of ">&" and $filehandle without the
>FH detour? (I want tempfile for its race avoidance and
>autoremoval of temp file features).
>
>Thanks and merry Christmas!
>
> Jens
You could try something like this:
use strict;
use warnings;
use IPC::Open3;
my $wtr;
open my $stdoutfd, '>', 'tmpfile1.txt' or die "can't open tmpfile1.txt";
open STDFH, ">&=", $stdoutfd or die "can't fdopen \$stdoutfd";
my $pid = open3($wtr, ">&STDFH", \*ERR, "dir c:\\");
while (<ERR>) {
print "Error: $_";
}
waitpid ($pid, 0) or die "$!";
close $stdoutfd or die "$!";
close STDFH or die "$!";
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2077
***************************************