• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

PHP executing program, but not grabbing values

Joined
Oct 10, 2009
Messages
929 (0.18/day)
System Name Desktop | Laptop
Processor AMD Ryzen 7 5800X3D | Intel Core i7 7700HQ
Motherboard MAG X570S Torpedo Max| Neptune KLS HM175
Cooling Corsair H100x | Twin fan, fin stack & heat pipes
Memory 32GB G.Skill F4-3600C16-8GVK @ 3600MHz / 16-16-16-36-1T | 16GB DDR4 @ 2400MHz / 17-17-17-39-2T
Video Card(s) EVGA RTX 3080 Ti FTW3 Ultra | GTX 1050 Ti 4GB
Storage Kingston KC3000 1TB + Kingston KC3000 2TB + Samsung 860 EVO 1TB | 970 Evo 500GB
Display(s) 32" Dell G3223Q (2160p @ 144Hz) | 17" IPS 1920x1080P
Case Fractal Meshify 2 Compact | Aspire V Nitro BE
Audio Device(s) ifi Audio ZEN DAC V2 + Focal Radiance / HyperX Solocast
Power Supply Super Flower Leadex V Platinum Pro 1000W | 150W
Mouse Razer Viper Ultimate | Logitech MX Anywhere 2
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:
Joined
Apr 2, 2007
Messages
2,817 (0.45/day)
Location
US
Processor Intel Q9400
Motherboard asus p5q-pro
Cooling Ultra120
Memory 6GB ddr2
Video Card(s) NVS 290
Storage 3TB + 1.5TB
Display(s) Samsung F2380
Case Silverstone Fortress FT02B
Audio Device(s) Creative X-Fi
Power Supply 750W PC P&C
Software win 7 ultimate 64bit
I guess those are not christian values...
 

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
26,956 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
Top