0

I want to execute a command in ubuntu terminal. When I directly run the command in terminal, it runs without any problem. But What I actually want to do is to execute this command via PHP.

chdir('/home/thilini/FYP/testone/bin/');    
exec('./mindtct input_folder/filename output_folder/filename'); 

The php code I wrote is shown above. I am using ubuntu 10.10 and the LAMP configuration. chdir is working fine and I have successfully moved from /var/www/ to /home/thilini/FYP/testone/bin/ (where I have the executable mindtct). But exec is not working. (mindtct is an executable which convert the file in the input folder to another format and store it in the output_folder under the given name). What am I doing wrong?

3
  • Sorry I actually used quotes. Updated Commented Sep 23, 2013 at 6:05
  • Check if ./mindtct is marked as executable (ls -l /home/thilini/FYP/testone/bin/mindtct). Commented Sep 23, 2013 at 6:19
  • It is marked as an executable. Read, write, execute privileges are given to all users on mindtct. Commented Sep 23, 2013 at 6:48

4 Answers 4

1

The problem was an issue in the path. A forward slash was missing.

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

Comments

0

If you're running below php 5.4,check "safe_mode" in your ini file.

http://www.php.net/manual/en/features.safe-mode.functions.php

3 Comments

Safe mode is turned off.
Read, write, execute privileges are given to all users.
This may not be the best comment, but since the binary permissions are executable for all and you are not getting any error have you ensure that the arguments to the binary are valid and have valid permissions?
0

You probably want

exec('./mindtct input_folder/filename output_folder/filename');

Maybe you should set error_reporting(-1) in your script so you get some errors

3 Comments

Where should I set error_report because I have not written any script?
in the top of your php file, in which you are making your exec. php.net/manual/en/function.error-reporting.php
Long time ago I was using PHP but this should work for setting error reporting stackoverflow.com/questions/9729000/… Have you also tested to fill in the absolute path to mindtct
0

You want to use shell_exec(), not exec().

shell_exec() executes a command in the terminal, whereas exec() opens an application.

$results = shell_exec('./mindtct input_folder/filename output_folder/filename');
print_r($results);

This will execute the command, store it in results, and then print_r the results in array format.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.