Snippet from my .pm :
@cmd = ("sudo", "/opt/energenie/RobBoilerControl.py", "ch", "on"); #MUST use sudo - no other method works reliably to access /dev/mem
$retVal = system(@cmd);
Log 3, "retVal = $retVal";
#system(@cmd) == 0 or Log 3, "system @cmd failed: " ; # test fails - system always returns -1 ?
#or die "system @cmd failed: $?";
system(@cmd) works fine but always returns -1 instead of 0. (I have since seen reference to this behaviour in fhem forum somewhere but have lost it now.)
I want that return value! The script's output end's up in the log very nicely and I don't want to rewrite it so as to run it with backticks but that's all I can think of right now.
Any thoughts please?
I get -1 if perl cannot execute the program.
I tried it with test.x:
#!/bin/sh
echo hallo
exit 7
and
perl -e 'my @a = ("test.x"); my $v = system(@a); printf "%04x\n",$v'
which returns
Zitathallo
0700
Thanks Rudolf.
Running perl directly is no problem; I get exactly the same behaviour with system() as you do - with correct status returns.
Running system() inside fhem (99_RobBoilerControl.pm in my case) it always returns -1 even though the associated python script succeeds.
I'm too much of a noob in fhem and perl to guess what is going wrong.
Bob