From 253b727a7cffb5d6d852a7689701468ee9c1451e Mon Sep 17 00:00:00 2001 From: borisneubert Date: Mon, 30 Mar 2015 08:12:25 +0000 Subject: [PATCH] 98_SubProcessTester: added some comments and an example how to use additional variables git-svn-id: https://svn.fhem.de/fhem/trunk@8336 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/SubProcess/98_SubProcessTester.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fhem/contrib/SubProcess/98_SubProcessTester.pm b/fhem/contrib/SubProcess/98_SubProcessTester.pm index b86dbe59d..bebda8c48 100644 --- a/fhem/contrib/SubProcess/98_SubProcessTester.pm +++ b/fhem/contrib/SubProcess/98_SubProcessTester.pm @@ -67,9 +67,13 @@ sub onRun($) { my $subprocess= shift; my $parent= $subprocess->parent(); Log3 undef, 1, "RUN RUN RUN RUN..."; + my $foobar= $subprocess->{foobar}; for(my $i= 0; $i< 10; $i++) { #Log3 undef, 1, "Step $i"; - print $parent "$i\n"; + # here we write something to the parent process + # this is received via the global select loop + # and evaluated in the ReadFn. + print $parent "$foobar $i\n"; $parent->flush(); sleep 5; } @@ -122,6 +126,7 @@ sub SubProcessTester_DoInit($) { $hash->{fhem}{subprocess}= undef; my $subprocess= SubProcess->new( { onRun => \&onRun, onExit => \&onExit } ); + $subprocess->{foobar}= "foo / bar"; my $pid= $subprocess->run(); return unless($pid); @@ -168,6 +173,8 @@ sub SubProcessTester_Read($) { my $subprocess= $hash->{fhem}{subprocess}; + # here we read from the global select loop what was + # written in the onRun function my ($bytes, $result); $bytes= sysread($subprocess->child(), $result, 1024*1024); if(defined($bytes)) {