From b4295832e2390ba6f58d04e5951b33f302df696f Mon Sep 17 00:00:00 2001 From: borisneubert Date: Wed, 1 Apr 2015 19:07:20 +0000 Subject: [PATCH] SubProcess.pm: added read function for convenience git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@8348 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/SubProcess.pm | 10 ++++++++++ fhem/contrib/SubProcess/98_SubProcessTester.pm | 8 ++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/fhem/FHEM/SubProcess.pm b/fhem/FHEM/SubProcess.pm index 2808caf43..075c4b93e 100644 --- a/fhem/FHEM/SubProcess.pm +++ b/fhem/FHEM/SubProcess.pm @@ -114,6 +114,16 @@ sub parent() { return $self->{parent}; } +# this function is called from the parent to read from the child +# returns undef on error or if nothing was read +sub read() { + + my $self= shift; + my ($bytes, $result); + $bytes= sysread($self->child(), $result, 1024*1024); + return defined($bytes) ? $result : undef; +} + # starts the child process sub run() { diff --git a/fhem/contrib/SubProcess/98_SubProcessTester.pm b/fhem/contrib/SubProcess/98_SubProcessTester.pm index bebda8c48..cae9638d6 100644 --- a/fhem/contrib/SubProcess/98_SubProcessTester.pm +++ b/fhem/contrib/SubProcess/98_SubProcessTester.pm @@ -175,14 +175,10 @@ sub SubProcessTester_Read($) { # 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)) { + my $result= $subprocess->read(); + if(defined($result)) { chomp $result; readingsSingleUpdate($hash, "step", $result, 1); - } else { - Log3 $hash, 2, "$name: $!"; - $result= undef; } return $result; }