1

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.

2
  • It should be noted I've been able to use command line shell command php and been able to make this work in command line but it breaks when I try to put it into test.php. Commented Mar 9, 2017 at 16:16
  • I checked the PHP.ini for "disable_functions". No line in the file contains that line. I found that at cyberciti.biz/faq/linux-unix-apache-lighttpd-phpini-disable-functions/ Commented Mar 9, 2017 at 16:50

1 Answer 1

1

http://php.net/manual/en/function.shell-exec.php

shell_exec — Execute command via shell and return the complete output as a string

Sign up to request clarification or add additional context in comments.

8 Comments

Tried that as well no luck. $test= exec_shell("MyProgram -f TestLogBinaryFileDate); echo $test; Does not work. I also tried pre tags as well no luck still blank.
@Dcross2017 - is shell_exec disabled in your php.ini? check disable_functions directive. Also, check that PHP is not running in safe mode.
remember after making changes to restart apache/nginx/php-fpm or whatever you have.
also, make sure you know what you are doing in terms of security - exposing shell_exec / exec is usually turned off via php.ini to browsers for a good reason.
I do not think these are turned off as the command php -r 'echo shell_exec("MyProgram -f TestLogBinaryFileDate");' works and displays text in command line. And echo exec('pwd'); echos out the full path of the test.php file to the browser successfully. Is there some place perhaps PHP requires the executable to be located for this to work?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.