summaryrefslogtreecommitdiffstats
path: root/perl-install/run_program.pm
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2003-11-23 21:33:02 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2003-11-23 21:33:02 +0000
commitb9956e388403d697c7daf51563f5a5f1bf5b111d (patch)
tree1ab1181b0993f788088c435ac73246049e23affb /perl-install/run_program.pm
parentc768768e3734c6e825c343e7b01a95970a13acd6 (diff)
downloaddrakx-backup-do-not-use-b9956e388403d697c7daf51563f5a5f1bf5b111d.tar
drakx-backup-do-not-use-b9956e388403d697c7daf51563f5a5f1bf5b111d.tar.gz
drakx-backup-do-not-use-b9956e388403d697c7daf51563f5a5f1bf5b111d.tar.bz2
drakx-backup-do-not-use-b9956e388403d697c7daf51563f5a5f1bf5b111d.tar.xz
drakx-backup-do-not-use-b9956e388403d697c7daf51563f5a5f1bf5b111d.zip
introduce bg_command object that enable to fork a sub that give back data
through STDOUT a la run_program::get_stdout but w/ arbitrary perl code instead of external program and in background
Diffstat (limited to 'perl-install/run_program.pm')
-rw-r--r--perl-install/run_program.pm23
1 files changed, 23 insertions, 0 deletions
diff --git a/perl-install/run_program.pm b/perl-install/run_program.pm
index 4ebce7249..0a53ffa39 100644
--- a/perl-install/run_program.pm
+++ b/perl-install/run_program.pm
@@ -127,3 +127,26 @@ sub raw {
}
}
+
+# run in background a sub that give back data through STDOUT a la run_program::get_stdout but w/ arbitrary perl code instead of external program
+package bg_command;
+
+sub new {
+ my ($class, $sub) = @_;
+ my $o = bless {}, $class;
+ if ($o->{pid} = open(my $fd, "-|")) {
+ $o->{fd} = $fd;
+ $o;
+ } else {
+ $sub->();
+ c::_exit(0);
+ }
+}
+
+sub DESTROY {
+ my ($o) = @_;
+ close $o->{fd} or warn "kid exited $?";
+ waitpid $o->{pid}, 0;
+}
+
+1;