in reply to Leaking a file descriptor into a child to use with /proc/self/fd/3

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.

Replies are listed 'Best First'.
Re^2: Leaking a file descriptor into a child to use with /proc/self/fd/3
by ewheeler (Novice) on Feb 26, 2020 at 23:47 UTC

    Actually grep was intended as a trivial example of something someone might run in exec after forking with reference to a FD that the parent opened. We don't actually need to grep the passwd file, I just wanted a simple example to show what was not working for us. $^F was the solution.