[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Wed May 12 10:13:57 2004 -->
- <!--x-from-r13: syrgpu ng culqrnhk.bet (Tyrgpu) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Redirecting STDOUT in perl to a socket -->
- <li><em>date</em>: Wed May 12 10:13:57 2004</li>
- <li><em>from</em>: fletch at phydeaux.org (Fletch)</li>
- <li><em>in-reply-to</em>: <<a href="msg00448.html">[email protected]</a>> (Christopher Fowler's message of "Wed, 12 May 2004 01:45:03 -0400")</li>
- <li><em>references</em>: <<a href="msg00448.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] Redirecting STDOUT in perl to a socket</li>
Christopher> I've created a socket from a client usins: $client =
Christopher> $server->accept();
Christopher> I'm trying to redirect 0,1,2 with the following code:
Christopher> *STDIN = $client; *STDOUT = $client; *STDERR =
Christopher> *STDOUT;
You don't just assign handles this way. You need to use open() (which
will actually do a dup2(2) on the fds underneath). The usual idiom
would be something like this:
open( SAVEOUT, "<&STDOUT" ) or warn "can't save stdout: $!\n";
open( STDOUT, "<&", $client ) or warn "can't dup to stdout: $!\n";
##
## ... yadda yadda yadda
##
open( STDOUT, "<&SAVEOUT" ) or warn "can't restore stdout: $!\n";
If you don't have a proper handle you can use "<&=" and the file
descriptor itself (e.g. $fd = fileno( $fh ); open( A, "<&=$fd" )).
See perldoc perlopentut and perldoc -f open for more details. You
might also check out IPC::Run, as I think it provides a shorthand to
run a child with things redirected to specific handles.
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org | Vincent, you should cease askin' \ o.O'
| scary questions." -- Jules =(___)=
| U
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00448" href="msg00448.html">[ale] Redirecting STDOUT in perl to a socket</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00468.html">[ale] External USB DVDRW for Linux</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00470.html">[ale] 802.11g for linux?</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00455.html">[ale] Redirecting STDOUT in perl to a socket</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00449.html">[ale] [Fwd: Re: [Discuss] Xandros 2.0 users]</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00469"><strong>Date</strong></a></li>
<li><a href="threads.html#00469"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>