0

I want to call a C++ program from PHP with apache server on Fedora 12 linux.
testprog is put in the same directory of the test php program.
I see the output of exec('ls -lrt') but not exec("testprog").
Please help.
The following are my php and cpp test programs.

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
<?php
echo exec('ls -lrt');
echo exec("testprog");
?>
 </body>
</html>

testprog.cpp

#include <iostream>
#include <algorithm>

int main() {
  int array[] = { 23, 5, -10, 0, 0, 321, 1, 2, 99, 30 };
  int elements = sizeof(array) / sizeof(array[0]); 
  std::sort(array, array + elements);
  for (int i = 0; i < elements; ++i) 
     std::cout << array[i] << ' ';
}
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by mutirelover
0

try:

echo exec("./testprog");

It works!
Thanks.
Why specifying the current path "." in the PATH environment is not good enough?
$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/sbin:.

0

Maybe the PHP exec() method doesn't search the BASH $PATH?
In general.the more specific you are about a path the better. Less assumptions to bite ya in the butt!

Please mark as solved.
Thanks

0

It works!
Thanks.
Why specifying the current path "." in the PATH environment is not good enough?
$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/sbin:.

Detection sometimes. $ Exec () function associated with.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.