Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question on a php syntax
#1
Hi,

I need to iterate through the following loop but the exec() line is failing to respond. What's the correct way of doing it?

TIA

<?php
//exec(python3 -c 'import gpio; print(gpio.ledsOn(0))'); //works when used from command line

$arrleds = array();

for ($x = 0; $x <= 6; $x++) {
    $arrleds[$x] = exec(python3 -c 'import gpio; print(gpio.ledsOn($x))');
    echo "The led status of ".$x "is: ".$arrleds[$x];
    echo " <br>";
}
?>
EDIT:

Solved with the following changes:

for ($x = 0; $x <= 6; $x++) {

    $cmd = exec("sudo python3 test.py ".$x);
    $arrleds[$x] = $cmd;
    echo "The led status is: ".$arrleds[$x];
    echo " <br>";
}
Reply


Messages In This Thread
Question on a php syntax - by ebolisa - Jan-14-2019, 10:25 AM
RE: Question on a php syntax - by nilamo - Jan-14-2019, 06:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  syntax error question - string mgallotti 5 1,318 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  question on syntax ebolisa 1 1,662 Oct-26-2019, 02:18 AM
Last Post: Larz60+
  simple syntax question speedskis777 7 3,598 Mar-11-2019, 02:26 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020