• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

PHP executing program, but not grabbing values

Joined
Oct 10, 2009
Messages
964 (0.17/day)
System Name Desktop
Processor AMD Ryzen 7 5800X3D
Motherboard MAG X570S Torpedo Max
Cooling Corsair H100x
Memory 64GB Corsair CMT64GX4M2C3600C18 @ 3600MHz / 18-19-19-39-1T
Video Card(s) EVGA RTX 3080 Ti FTW3 Ultra
Storage Kingston KC3000 1TB + Kingston KC3000 2TB + Samsung 860 EVO 1TB
Display(s) 32" Dell G3223Q (2160p @ 144Hz)
Case Fractal Meshify 2 Compact
Audio Device(s) ifi Audio ZEN DAC V2 + Focal Radiance / HyperX Solocast
Power Supply Super Flower Leadex V Platinum Pro 1000W
Mouse Razer Viper Ultimate
Keyboard Razer Huntsman V2 Optical (Linear Red)
Software Windows 11 Pro x64
Hey there.

I have a PHP script executing multiple C programs (which have been placed in /usr/local/bin/) using 'backticks', like so:

$data= `sudo CProg`;

When the C program has executed, it will print to console the values:

5,75

The PHP is then meant to grab the comma-separated values, then 'explode' them and save each into corresponding values:

$dataValues = array_map('trim',explode(",", $data));

$valueOne = $dataValues[0];
$valueTwo= $dataValues[1];

echo "<br>Value 1: $dataValues[0] <br> Value 2: $dataValues[1]<br>";

The problem is the PHP only seems to grab the commas with the echo resulting in only ' , ' being displayed. I know for a fact that this script and program should work as it was working before I had to fully rebuild my Linux (I know, I should have had a backup).

EDIT for reference: I had forgotten to give www-data the ability to execute programs using sudo
 
Last edited:
I guess those are not christian values...
 
Back
Top