If I do the following in Bash, then I get the PID of the remotely started mbuffer, and even though mbuffer is still running, I get the terminal back, which is what I want.
read -r pid < <(ssh 10.10.10.47 'nohup /opt/omni/bin/mbuffer -4 -s 128k -m 2G -v 0 -q -I 8023 >/tmp/mtest </dev/null 2>/tmp/mtest.err & echo $!') echo $pid Now I would like to do the same in Perl, so I try
use Capture::Tiny 'capture'; my ($stdout, $stderr, $exit) = capture { system("read -r pid < <(ssh 10.10.10.47 'nohup /opt/omni/bin/mbuffer -4 -s 128k -m 2G -v 0 -q -I 8023 >/tmp/mtest </dev/null 2>/tmp/mtest.err & echo $!'); echo \$pid"); }; print "stdout $stdout\n"; print "stderr $stderr\n"; print "exit $exit\n"; Here I would have expected that $stdout would have given me the PID from the last echo command, but I got nothing.
Question
How do I get the PID of the remotely executed mbuffer in Perl, and so the Perl script isn't waiting for mbuffer to exit before continuing?
q{}. You escaped your\$pid, but you failed to escape$!. It's therefore possible that an error is being reported but not displayed to you.q{}work insidesystem(). It is ignored it seams.