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?
The problem was an issue in the path. A forward slash was missing.
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
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
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
Related
I'm trying to run the PHP exec() command, but it doesn't execute. It works on NGINX but doesn't work on Apache. I'm using Windows.
$cmdex = exec('cmd /c C:\nginx-1.20.2\html\pythonbatch.bat');
echo $cmdex;
I've tried different solutions like changing the permission and config files, but it doesn't work. When I run the PHP program, it outputs this but doesn't execute:
C:\Apache24\htdocs>exit
PHP works fine in general, but when I do anything that has to do with executing, it doesn't work.
EDIT: To clarify, PHP works when executing the command standalone but doesn't work in browser.
I have a very strange problem.
I'm trying to make a program that executes shell_exec() in PHP with NMAP.
The problem comes when I put shell_exec("nmap --version"), because it returns me version 4.11, but when I put it directly on shell, it returns me version 7.01.
When using shell_exec you should always use the full path to the executable.
I'm trying to run a ROS shell program on the server through php on Ubuntu 14.04. I have tried using system, exec, shell_exec but nothing happens and I don't get any output. The system call is the following:
echo shell_exec("/opt/ros/indigo/bin/rosrun gazebo_ros spawn_model -database Part_A -gazebo -model Part_A");
What are the limitations of using system or exec to run any shell command through php on a server?
I don't care as much about the output of the command as for its execution. I think the problem has to do with the fact that PHP doesn't have any PATH like shell does so it can't find any applications without specifying the exact location. How can I make PHP se the same PATH shell does?
The problem was that the apache user and the environment in which the bash commands are running are not set up correctly. I followed the instructions from this answer but instead of using "source" I used "." and instead of using the source.bash file I used the source.sh file. I also set all the environment variables that had to do with ros or gazebo using the putenv() function.
exec("fun.exe input/input.txt ");
I want to run an CUDA program in PHP,
the task is:
load data from an input.txt. (argument)
calculating.
write an output.txt.
and PHP read ouput.txt to do next task.
In server1(Apache ,Windows XP), it can run perfectly,
but in server2,3(Apache, Windows 7),the output is wrong.
The program doesn't crash and there's no any error message in the page,
it seems like something wrong during the execution.
Next I try exec the All CPU-side version (same calculation),server2,3 can run correctly.
If I exec the fun.exe(CUDA version) in server2,3 directly(double click or in command line),the program also run perfectly.
Any idea on why server2,3 can't run the program? Thanks.
First, try using the full path to the executable. Then the full path to the input file too.
If that doesn't work, then try modifying the file permissions (try with full 777 permissions, if that works then you know where your problem lies).
Try to use the entire path (windows version using backslash).
I am working on Windows server and able to run command from command prompt
c:> %convertxls% {some args....}
But when I run same command from php script
*shell_exec(%convertxls% ..... 2>&1);*
it gives me error as
%convertxls% is not recognized as an internal or external command, operable program or batch file.
I think when I am running command from command prompt, it run for user which logged in. And when I run the php script it run for "www" user for which path is not set.
Can anybody tell me where I am doing mistake?
*Note: I haven't written complete command.
Supply the full path to the executable.
ignacio right,I wanted to add one more point that ignacio did not specify .
Check the parameter disable_functions in the php.ini .
maybe this function is not allowed.
This sounds like the environment variable %convertxls% is not set.
You can use putenv() to set it; alternatively, as Ignacio already says, specify the full path.