Hi, sorry, it's really unclear what you are trying to do, because of the shelling out and all that. Also note that you do not check to see that your open call succeeded.

Maybe this will help?

Unix::Passwd::File

$ perl -MUnix::Passwd::File -MData::Dumper -Mstrict -wE 'say Dumper Un +ix::Passwd::File::get_user(user => "root")'
$VAR1 = [ 200, 'OK', { 'gecos' => 'System Administrator', 'home' => '/var/root', 'uid' => '0', 'pass' => '*', 'gid' => '0', 'user' => 'root', 'shell' => '/bin/sh' } ];

... or maybe:

Path::Tiny

$ perl -MPath::Tiny -Mstrict -wE 'print for grep {/root/} path("/etc/p +asswd")->lines'
root:*:0:0:System Administrator:/var/root:/bin/sh daemon:*:1:1:System Services:/var/root:/usr/bin/false _cvmsroot:*:212:212:CVMS Root:/var/empty:/usr/bin/false

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Leaking a file descriptor into a child to use with /proc/self/fd/3 by 1nickt
in thread Leaking a file descriptor into a child to use with /proc/self/fd/3 by ewheeler

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.