Reputation: 11
I have a program that outputs data in command line.
MyProgram -d "02/02016/12:00-03/02/2016/12:00"
I am merely trying to display results from a compiled c program on Linux to the webpage. There are additional flags besides file(-f filename) and date(-d "datetime or datetime range"). There are other shell command flags available to the program but they have no impact on the display format of the text itself.
This results in output formated in command line similar to the following. The actual results here is of little consequence. It displays a list or records in a format similar to the following on the back end.
I am attempting to display the results below to the PHP front end web page.
------------------------------------------------------------------------------------
<record_id_number_here> <date_stamp_tex><someflag_value><event_type_number>
<Some event status text information>
-----------------------------------------------------------------------------------
Things I've tried see test.PHP code below. I am looking for just one working way.
test.php
<?php
echo "ran as user:".exec("whoami");
echo "test1<br />";
echo exec("MyProgram -f TestLogBinaryFileDate");
echo "test2<br />";
echo system("MyProgram -f TestLogBinaryFileDate");
echo "test3<br />";
echo popen("MyProgram -f TestLogBinaryFileDate");
echo "test4<br />";
echo passthru("MyProgram -f TestLogBinaryFileDate");
echo "tests calls complete";
?>
Each attempt to get the results from each of those functions did not stop PHP from continuing nor did it display any record data text that should have been.
MyProgram I've had even tried having the Apache user set as owner of the file compiled command line application and even moved the application into the the website we root directory where the webpage test.php resides.
Environments Linux ( fedora 22 or red hat Linux in the future), Mariadb, PHP 5.6.8
I have no doubt I will be updating this with more information of what worked and did not work.
I've see posts that talk about safemode directory this does not work as safemode PHP was droped in 5.4 and deprecated in 5.3 therefore safemode should not be the problem.
Upvotes: 1
Views: 89
Reputation: 12445
http://php.net/manual/en/function.shell-exec.php
shell_exec — Execute command via shell and return the complete output as a string
Upvotes: 1