0

Newbie (PHP). Trying to call a C++ executable (a.out) from php. but unable to do so. Can run the a.out script in terminal as shown in pic here. Using netbeans and mac.

My PHP Code:

My PHP Code

My Terminal Output:

Terminal output

My Code output:

My Code output

My C++ Source File:

C++ Source File

Output after using escapeshellargument:

escapshell

My PHP Version:

PHP Version

Read Permissions for the file :

Read Permissions

8
  • 1
    Are you in the right directory? What does echo getcwd(); show? Commented Apr 22, 2015 at 5:48
  • What PHP version are you running? Commented Apr 22, 2015 at 5:58
  • Are the files involved in your parameters readable by the user as which your web server or php-fpm is running? Commented Apr 22, 2015 at 6:05
  • @minitech My first command in the php script checks the contents of the current directory (in web browser output) and the terminal is executing the command correctly. Commented Apr 22, 2015 at 7:01
  • 1
    Please don't use screenshot but use code formatting instead. Commented Apr 22, 2015 at 7:18

1 Answer 1

2

Your a.out may be expecting exactly three parameters, but is only given two. The third parameter will be empty in the exec call.

Try this:

$param3 = escapeshellarg(""); // Will make it "''" => empty but existing to a.out
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your reply. I made the changes. Size of array is 1 now but still I don't see any output. I have also attached the source file for a.out.
I also tried escapshellarg for param1 and param2 but still I don't see any output like in the terminal window. Good thing is now it shows that size of array is 1.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.