Search code examples
shellraspberry-piphplighttpd

PHP shell_exec with lighttpd on Raspberry pi


I'm creating simple Wi-Fi scanning script on raspberry pi. for that I used lighttp web server and php. I can run php without any issues. but when I run shell script using php it not properly return the results. my code is like this

<?php
$ssidoutput = shell_exec('. /var/www/html/scanssid.sh');
sleep(3);
echo "<pre>$ssidoutput </pre>";
#var_dump($ssidoutput );
?>

but when I executing this I only get one SSID print on my web browser. but when I run shell script I can see full list of SSIDs on my terminal. I thought this is some kind of execution time issue and add sleep value. but that wont fix my issue. how to fix this. my shell script contain nothing but command to scan the SSIDs for Raspbian


Solution

  • I think you are facing this because "shell_exec" in php not able to read multi-line output. easiest think to do is modify your script to print All SSID on single line. may be comma separated and then process in php to replace comma with new line.