[30831] in Perl-Users-Digest
Perl-Users Digest, Issue: 2076 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 25 00:09:42 2008
Date: Wed, 24 Dec 2008 21:09:06 -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 Wed, 24 Dec 2008 Volume: 11 Number: 2076
Today's topics:
Buffering problem with 'open' - ideas ? <asuter@cisco.com>
Re: Buffering problem with 'open' - ideas ? <someone@example.com>
Re: Chart::Gnuplot problem (Vicky Conlan)
Re: Chart::Gnuplot problem taiwai@gmail.com
Re: family naturism preteen, naturist preteen, young pr trustinoli@gmail.com
Re: Press a button <pod69@gmx.net>
Re: Press a button <tadmc@seesig.invalid>
Re: Press a button <pod69@gmx.net>
Re: Press a button <tadmc@seesig.invalid>
Re: regular expression like AND match <peter@makholm.net>
Re: regular expression like AND match sln@netherlands.com
Understanding tempfile and open3 usenet@schweikhardt.net
Re: Understanding tempfile and open3 <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Dec 2008 17:33:20 -0800
From: "Asim Suter" <asuter@cisco.com>
Subject: Buffering problem with 'open' - ideas ?
Message-Id: <1230168800.607060@sj-nntpcache-2.cisco.com>
Greetings!
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 ?
This is with Perl v5.6.1 on
> uname -a
Linux m_c_name 2.6.9-22.0.2.ELsmp #1 SMP Thu Jan 5 17:11:56 EST 2006 x86_64
unknown unknown GNU/Linux
Please let me know if you need any more information.
Thanks in advance.
Asim
------------------------------
Date: Wed, 24 Dec 2008 19:39:56 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Buffering problem with 'open' - ideas ?
Message-Id: <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
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
------------------------------
Date: Wed, 24 Dec 2008 11:47:57 +0000 (UTC)
From: comps@riffraff.plig.net (Vicky Conlan)
Subject: Re: Chart::Gnuplot problem
Message-Id: <git7hd$2jr8$1@magenta.plig.net>
According to <jimsgibson@gmail.com>:
>> "/tmp/2sp97fafGp/plot", line 1: undefined variable: noenhanced
>Did you look in directory /tmp/2sp97fafGp for a file called plot? If
Yeah, first thing I checked, there is pretty much nothing in /tmp/. I
assumed it cleaned it up on exit. (I did wonder if /tmp/ wasn't writable,
it looks so empty, but it appears to be ok)
>you look at the source of Chart::Gnuplot:
>
>(<http://search.cpan.org/src/KWMAK/Chart-Gnuplot-0.06/lib/Chart/Gnuplot.
>pm>),
>
>it looks like it creates a file of that name containing commands to
>gnuplot. Some of those commands, such as 'title' or 'set xlabel' can
>contain the string 'noenhanced'. The question is why the string
>'noenhanced' is being interpreted as a variable.
Yeah, I had a look, but I was hoping (in that "someone has probably done
it before" way the world of Perl is :-) I may not have to delve too far
into the guts of it.
>You could also copy the source of Chart::Gnuplot and modify it so that
>it does not clean up its files (remove 'CLEANUP => 1' or replace it
>with 'CLEANUP => 0' ).
That's a good idea.
>If you can get the file, does it have the string 'noenhanced' in line
>1? If not, then you might have a line-ending problem, where the entire
>file is being interpreted as a single line.
It's very odd.
>Sometimes a program will explicitly set a variable to its default
>value, just for the sake of explicitness. Sometimes it is to override a
>previous, non-default value. Several items can be 'enhanced', so you
>don't know which one is being used unless you can inspect the plot
>file.
Yeah. I just don't get why one copy would be working differently to the
other.
>> The only possibly relevant difference I can spot is that the working copy
>> uses gnuplot 4.2 patchlevel 3, the not-working uses 4.0 patchlevel 0
>That is a pretty significant difference.
True, but it's a gnuplot difference, not a Perl difference, and the error
struck me as a Perl error not a gnuplot one. But actually, you're right, it's
a gnuplot error. *slaps forehead*
Ok, it may be time for me to go bark up a different tree.
>Is there any chance you can
>upgrade the non-working system to version 4.2?
I asked for the later version to be installed and they've put it into a
different path (with the existing one remaining where it is), so I'll have
to work out how to convince Chart::Gnuplot to look on a different path for
the executable.
>To help you more, we would need to see some code and information about
>versions: Perl, Chart::Gnuplot, etc.
Versions are consistent between the two machine, Perl 5.8.8 and
Chart::Gnuplot 0.05
The only difference does seem to be the gnuplot version, which I'd dismissed
as irrelevant, but I'll see if I can prod the module to find the newer version
Thanks for the ideas.
--
------------------------------
Date: Wed, 24 Dec 2008 05:43:36 -0800 (PST)
From: taiwai@gmail.com
Subject: Re: Chart::Gnuplot problem
Message-Id: <3d680043-71e2-4239-8d99-5d0c3d094a2a@o40g2000prn.googlegroups.com>
On 12$B7n(B24$BF|(B, $B>e8a(B7$B;~(B18$BJ,(B, co...@riffraff.plig.net (Vicky Conlan) wrote:
> I've got a little bit of a problem. I'm not sure if I'm doing something
> daft or if I've got a bad installation, but because I don't have any control
> over the install I'm having trouble telling what is wrong.
>
> So I've got a fairly simple script which I developed on a freeBSD machine
> whilst I waited for the install on the machine at work. It is fairly basic,
> it has a couple of datasets, blah blah, then it draws some filled curves.
> And it works fine. (output:http://comps.org/fig/simple.png)
>
> Then I tried exactly the same code on a solaris 10 zone and got the ever-
> so-unhelpful error:
>
> "/tmp/2sp97fafGp/plot", line 1: undefined variable: noenhanced
>
> There is no reference to noenhanced in /my/ code. There are various bits
> in the Gnuplot module that mention it, but noenhanced is the default, so I
> don't see why it would work on one and not the other.
>
> The only possibly relevant difference I can spot is that the working copy
> uses gnuplot 4.2 patchlevel 3, the not-working uses 4.0 patchlevel 0
>
> Any chance anyone has experienced this and can give me some subtle hints
> about what could be the problem? (thanks)
>
> --
Hi,
I read the discussion in another forum (http://www.1-script.com/forums/
Chart-Gnuplot-problem-article104335--6.htm). I know that your system
has two versions of Gnuplot installed. You can tell Chart::Gnuplot
which one to use by the option "gnuplot", e.g.
$chart = Chart::Gnuplot->new(
gnuplot => "/usr/bin/gnuplot-4.2.3",
......
);
The filename of the temp file (i.e. "/tmp/2sp97fafGp/plot") is saved
in "$chart->{_script}". If you want to get the Gnuplot command file,
you may copy "$chart->{_script}" to another file after "$chart->plot2d
(...)".
Hope these help.
------------------------------
Date: Wed, 24 Dec 2008 10:03:15 -0800 (PST)
From: trustinoli@gmail.com
Subject: Re: family naturism preteen, naturist preteen, young preteen in thong, teen bbs, innocent preteens!
Message-Id: <109b8f03-80b9-4922-a7a9-9dd06190ca61@b41g2000pra.googlegroups.com>
My handsome boyfriend is a real fucking machine! He can drill my wet
dripping slit with his immense pecker for hours nonstop. Now you are
offered the best videos selected from our young home porn collection.
Young teenage tube: http://teentube.com.cn/
This guy knows how to make me experience the strongest emotions in my
life and to tell the truth I cum time after time when he=92s working my
tight slit with his big meaty sausage. Now we are going to prove you
that! Sit back and enjoy our amateur movies: http://teentube.com.cn/
Tags: young teenage tube, fucking machine, wet dripping slit, young
home porn, tight slit, amateur movies
------------------------------
Date: Wed, 24 Dec 2008 14:58:20 +0100
From: pod <pod69@gmx.net>
Subject: Re: Press a button
Message-Id: <49523fff$0$2623$91cee783@newsreader01.highway.telekom.at>
Hello
My aim is to make a script that pushes 2 buttons on my routers
webinterface so that the router can get a new ip. The html shows the
code of the button. I just have to press somehow the button is the html
code not enough information to make a little script that pushes the
Disconnect button?
I found something on the web but i dont know if its useful an example
that searches for someting and also presses a button?
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
# Create a request
my $req = HTTP::Request->new(POST => 'http://search.cpan.org/search');
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
}
else {
print $res->status_line, "\n";
}
pod schrieb:
> Hello,
>
> I want to make a perl script that presses the Disconnect button of the
> below html code. I found some code but still I am not able to press the
> button. Can someone help me please with some code?
>
> thx
>
> <form name='PPPConn0' action='/cgi/b/is/' method='post'>
> <input type='hidden' name='0' value=''>
> <input type='hidden' name='1' value=''>
> <input type='hidden' name='2' value='279867884'>
> <hr>
> <div class='contentitem'>
> <table cellspacing='0' cellpadding='0'>
> <tr><td class='icon' valign='top' width='100px'><img
> src='/images/cintgrxl.gif' alt='Internet Connection OK'></td>
> <td class='data' valign='top'><table cellspacing='0'
> cellpadding='0'><tr><td align='left'><span
> class='itemtitle'>INTERNET</span></td><td align='right'><input
> type='button' name='13' value='Disconnect'
> onClick='submitForm(document.PPPConn0,13,0,"INTERNET","",0,"")' >
> </td></tr>
> <tr><td colspan='2'><input type='hidden' name='5' value="2">
> <br><table cellspacing='0' cellpadding='0' width='100%'><tr><td
> width='40' valign='top'><img src='/images/bull__md.gif' alt=''></td><td
> valign='top'>
> <span class='blocktitle'><a
> href="javascript:GoAndRemember('/cgi/b/is/_pppoa_/ov/',
> 'name=INTERNET')">View more...</a></span><br>
> </form>
------------------------------
Date: Wed, 24 Dec 2008 08:42:00 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Press a button
Message-Id: <slrngl4iho.os2.tadmc@tadmc30.sbcglobal.net>
[ Please do not top-post! ]
pod <pod69@gmx.net> wrote:
> My aim is to make a script that pushes 2 buttons on my routers
> webinterface so that the router can get a new ip. The html shows the
> code of the button. I just have to press somehow the button is the html
> code not enough information to make a little script that pushes the
> Disconnect button?
Yes, the html code is not enough (because there is some JavaScript
in the middle).
You need to discover what HTTP request is being sent.
> I found something on the web but i dont know if its useful an example
> that searches for someting and also presses a button?
>
> use LWP::UserAgent;
This module (or WWW::Mechanize which subclasses it) will almost
surely be part of the solution.
How to make it into the solution depends on ...
... what HTTP request is being sent.
[ snip upside-down quote ]
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 24 Dec 2008 16:25:59 +0100
From: pod <pod69@gmx.net>
Subject: Re: Press a button
Message-Id: <4952549e$0$2634$91cee783@newsreader01.highway.telekom.at>
Hi
I used wireshark to have a look whats going on I hope its enough what i
have found?
This is the button that should be pressed:
<input type='button' name='13' value='Disconnect'
onClick='submitForm(document.PPPConn,13,0,"INTERNET","",0,"")' >
The javascript code should be:
GET /util.js HTTP/1.1
Host: 10.0.0.138
User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.5)
Gecko/2008120121 Firefox/3.0.5
Accept: */*
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://10.0.0.138/cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET
HTTP/1.0 200 OK
Cache-Control: no-cache
Expires: -1
Content-Type: application/x-javascript
This should be the method
// Function submit a form
function submitForm(theForm, actionNo, flags, primkey, confirmMsg,
anchor, eval_code)
{
var VALIDATE = 0x01;
var CONFIRM = 0x02;
var EVAL = 0x04;
if (flags && (flags & CONFIRM))
if (!confirm(confirmMsg)) return;
if (flags && (flags & VALIDATE))
if (!validate(theForm, actionNo)) return;
if (flags && (flags & EVAL) && eval_code)
eval(eval_code);
if (actionNo > 0)
theForm.elements[0].value = actionNo;
if (primkey)
theForm.elements[1].value = primkey;
var customArgs = new String("");
if (g_state[TYPE].length > 0)
{
customArgs += "name="+escape(g_state[NAME]);
if (g_state[KEY].length > 0)
customArgs += "&" + g_urlArgs[KEY] + "=" + g_state[KEY];
}
if (g_state[TID].length > 0)
{
if (customArgs != "")
customArgs += "&";
customArgs += g_urlArgs[TID] + "=" + g_state[TID];
}
theForm.action += constructArgString(customArgs);
if (anchor)
theForm.action += "#" + anchor;
theForm.submit();
disable_fields(theForm);
}
This is from 10.0.0.1 -> 10.0.0.138
POST /cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET HTTP/1.1
Host: 10.0.0.138
User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.5)
Gecko/2008120121 Firefox/3.0.5
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
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://10.0.0.138/cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
0=13&1=INTERNET&2=3342349270&5=2
The answer from 10.0.0.138 -> 10.0.0.1
is html code a few lines:
HTTP/1.0 200 OK
Cache-Control: no-cache
Expires: -1
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Thomson Gateway - INTERNET</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">var g_navitem = -1;</script>
<script type="text/javascript"> var g_focus = -1;</script>
<script type='text/javascript' src='/util.js'></script>
<link rel="stylesheet" type="text/css" href="/styles.css">
</head>
<body onload="setFocus();" height="100%
........................................................................
thx
Tad J McClellan schrieb:
> [ Please do not top-post! ]
>
>
> pod <pod69@gmx.net> wrote:
>
>> My aim is to make a script that pushes 2 buttons on my routers
>> webinterface so that the router can get a new ip. The html shows the
>> code of the button. I just have to press somehow the button is the html
>> code not enough information to make a little script that pushes the
>> Disconnect button?
>
>
> Yes, the html code is not enough (because there is some JavaScript
> in the middle).
>
> You need to discover what HTTP request is being sent.
>
>
>> I found something on the web but i dont know if its useful an example
>> that searches for someting and also presses a button?
>>
>> use LWP::UserAgent;
>
>
> This module (or WWW::Mechanize which subclasses it) will almost
> surely be part of the solution.
>
> How to make it into the solution depends on ...
>
> ... what HTTP request is being sent.
>
>
> [ snip upside-down quote ]
>
>
------------------------------
Date: Wed, 24 Dec 2008 11:25:11 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Press a button
Message-Id: <slrngl4s3n.qek.tadmc@tadmc30.sbcglobal.net>
[ You will enter the killfile the next time you top-post.
Please do not top-post!
]
pod <pod69@gmx.net> wrote:
> I used wireshark to have a look whats going on I hope its enough
> This is the button that should be pressed:
Don't need "the button".
> The javascript code should be:
Don't need the javascript.
> POST /cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET HTTP/1.1
> Host: 10.0.0.138
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.5)
> Gecko/2008120121 Firefox/3.0.5
> 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
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://10.0.0.138/cgi/b/is/_pppoa_/ov/?be=0&l0=1&l1=2&name=INTERNET
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 32
>
> 0=13&1=INTERNET&2=3342349270&5=2
There is the post request that is needed.
Now use LWP::UserAgent to send that same request.
There are 4 values to set, named "0", "1", "2" and "5".
> Tad J McClellan schrieb:
>> [ Please do not top-post! ]
I asked nicely already.
>> [ snip upside-down quote ]
[ snip yet more upside-down foolishness ]
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 24 Dec 2008 10:27:10 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: regular expression like AND match
Message-Id: <87vdt9vs7l.fsf@vps1.hacking.dk>
Mirco Wahab <wahab-mail@gmx.de> writes:
> my $reg = join '|', map $_.'(?{$bts|='.(1<<$cnt++).'})', @strings;
Wow. Simple look ahead assertions would du just fine. Don't turn it
into rocket science just because the single regexp requirement is
silly.
//Makholm
------------------------------
Date: Wed, 24 Dec 2008 18:38:54 GMT
From: sln@netherlands.com
Subject: Re: regular expression like AND match
Message-Id: <6705l4p9og8tj87klv6lmg9oet7r0b3buc@4ax.com>
On Tue, 23 Dec 2008 06:16:55 -0800 (PST), ikeon <shay.rozen@gmail.com> wrote:
>The case is that I need to search for a couple of strings in a line. I
>don't know the order that they will be matched and I need them all to
>be matched.
>like if (string1|string2|string3) can find one of the strings (OR) , I
>need it to match all of the strings (like AND) and again - I don't
>know the order that they will appear.
>I know how to do it if I will check the line 3 times in some loop, but
>I need to know if it can be done in one regular expression.
>
>Thanks,
Alot of good suggestions already.
I guess you could do something like this as well.
sln
---------------------------------------------------
use strict;
use warnings;
my @strings = ("find this", "that too", "and other");
my $patrx = join '|', @strings;
$patrx = qr/$patrx/;
my $fpos = tell(DATA);
## To match all or some -
while (<DATA>)
{
chomp; next if (!length);
my %seen = ();
if (s/($patrx)/$seen{$1}=$1/eg && (keys %seen) == @strings)
{
# matched all
my $found = join ',', keys %seen;
print "found ALL: '$found'\n\tin '$_'\n";
}
else
{
# matched some or none
my $found = join ',', keys %seen;
print "found ".(keys %seen)."/".@strings.": '$found'\n\t in '$_'\n";
}
}
print "====================\n";
seek(DATA, $fpos, 0);
## To match any -
while (<DATA>)
{
chomp; next if (!length);
if (/($patrx)/)
{
# matched one
print "found '$1'\n\t in '$_'\n";
}
}
__DATA__
first line string1
second line string1 string2 find this
third line string1 string2 string3
find this", "that too", "and other
------------------------------
Date: Wed, 24 Dec 2008 15:50:33 -0800 (PST)
From: usenet@schweikhardt.net
Subject: Understanding tempfile and open3
Message-Id: <667240ab-b1b0-4b25-8842-0a30fba9821e@q30g2000prq.googlegroups.com>
hello, world\n
I've read the perlfaq#8 up and down, can spell File::Temp backwards,
but still, I'm puzzled because no matter what I do, I get an empty
tempfile when it clearly should not be empty. Here's what I want:
Run "gcc -E -v -dM -x -c /dev/null" and write stderr to a temp file
while reading stderr from some handle (exactly so. Suggestions like
"write two temp files; see perlfaq8" are inelegant). The way I try to
combine tempfile and open3 is not correct and I want to know my
mistake. Here's a complete program to illustrate the issue:
#!/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>.
my $pid = open3 (gensym, $filehandle, \*ERR, @cmd);
while (<ERR>) {
print $_; # This works fine.
}
waitpid ($pid, 0) or die "$!";
close $filehandle or die "$!";
# What I get: 0 bytes even though it should be many lines.
# I would have expected $filename to be more than a zero-length
file...
# What exactly is the relation between $filehandle and $filename?
system ('wc', $filename);
The output is:
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
/usr/libexec/cc1 -E -quiet -v -D_LONGLONG /dev/null -dM
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include
End of search list.
0 0 0 ./predef-Om1rvd.h
The part form "Using built-in specs." to "End of search list." is
gcc's stderr.
Stdout has about 50 "#define" directives that you can see when running
the gcc command from the shell command line.
Thanks for any clue. Merry Christmas!
Regards,
Jens
------------------------------
Date: Wed, 24 Dec 2008 21:34:25 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Understanding tempfile and open3
Message-Id: <x74p0t9e4u.fsf@stemsystems.com>
>>>>> "u" == usenet <usenet@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.
u> while (<ERR>) {
u> print $_; # This works fine.
u> }
so just print that to the temp handle:
print $filehandle $_ ;
or since you don't care about the other handles, just slurp it and
print:
print $filehandle <ERR> ;
you can even use File::Slurp and not need to create the tempfile and its
handle:
use File::Slurp
write_file( 'pick_a_file_name', <ERR> ) ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
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 2076
***************************************