Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Lots of djb programs and related/similar utilities (e.g. sslclient) have interfaces that want data written to or read from specific file descriptors. (With sslclient: "sslclient runs prog, with file descriptors 6 and 7 reading from and writing to a child process").

Maybe I'm interpreting things incorrectly, but is there a way to open a file on a specific fd in Perl? I tried the following with open, but it seems to fail if the fd's not already open:

$ perl -lwe 'open STDOUT, ">&=6" or die ">&=6: $!"' >&=6: Bad file descriptor at -e line 1. $ perl -lwe 'open STDOUT, ">&=6" or die ">&=6: $!"' 6>/dev/null

The goal is to provide a similar interface, like:

# Don't use this - DOESN'T WORK open my $to_child, ">&=6" or die ">&=6: $!"; open my $from_child, "<&=7" or die "<&=7: $!"; die "fork:$!" if not defined(my $pid = fork); if ($pid) { print $to_child "data for child\n"; my $ret = <$from_child>; } else { exec { "sub-program" } "sub-program", @args; }

In reply to Open a file on a specific file descriptor? by benizi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-25 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found