in reply to Capture output from command under su

if you are interested in the exit status (not the output, as grep pointed out) of /usr/bin/passwd, you could use
$cmd = "/bin/su $user -c '/usr/bin/passwd $user; exit \$?'";

as your constructed $cmd, although I'm pretty sure that su sets its own exit status to that of the invoked program.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}