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; }