Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: File handle passing issue under *nix

by McA (Curate)
on Sep 30, 2013 at 19:16 UTC ( #1056411=note: print w/ replies, xml ) Need Help??


in reply to [SOLVED] File handle passing issue under *nix

Hi vsespb,

as I have to do penance for my sarcastic answer in another thread of today, here my points:

1) You subcommand2.pl test is IMHO a false positive. As soon as you read twice you also get this stuck behaviour. Try this:

open IN, "<&", $ARGV[0] or die $!; binmode IN; my $s = <IN>; print "line: $s"; print "Attempt to read twice:"; $s = <IN>; print "line: $s"; close IN;

So, it's the same as subcommand1.pl. You're just kidding yourself.

2) As soon as you modify your main.pl to the following, it works:

use strict; use warnings; use IO::Handle; $^F = 100; pipe READHANDLE,WRITEHANDLE; binmode READHANDLE; binmode WRITEHANDLE; WRITEHANDLE->autoflush; READHANDLE->autoflush; unless (fork()){ close WRITEHANDLE or die $!; exec $^X, $ARGV[0], fileno(READHANDLE); die; } close READHANDLE or die $!; print WRITEHANDLE "Test!\n"; close WRITEHANDLE; wait;

You see, that the unnecessary ends of the pipe are closed. See http://man7.org/linux/man-pages/man2/pipe.2.html for the description.

Best regards
McA


Comment on Re: File handle passing issue under *nix
Select or Download Code
Re^2: File handle passing issue under *nix
by vsespb (Hermit) on Sep 30, 2013 at 19:32 UTC
    1) You subcommand2.pl test is IMHO a false positive.
    Indeed, but my intention was to proof that it at least can read something and not hang (so, exec() call works like expected etc).
    2) As soon as you modify your main.pl to the following, it works
    Damn! You are right! I was trying version which closes READHANDLE, but forgot about WRITEHANDLE ! Thank you. I think it's solved now!

    p.s.
    I upvoted your sarcastic post, it looks acceptable to me.

      You're welcome. McA

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056411]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-08-31 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls