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.
Related
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.
I'm trying to use the exec() PHP function on a system that run on HHVM.
Unfortunately, the command (even a simple echo) return an empty string, without any error. When I try the command inside terminal as root the output is correct.
PHP Safe mode is off, I guess this is a permission issue but I don't know how to solve it.
I've updated HHVM to 3.x, and it's now working like a charm.
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
I am trying to get the path to certain exe's using the where command in the command prompt on windows.
Here is what i did in command prompt.
where g++
where java
where javac
where python
All of these are giving the correct output of the path in the console window which indicated that I have set the environment variables correctly.
But now When i try to run the commands using the shell_exec() function in PHP, only the call to where java and where python gives the correct output. I was even able to successfully execute a respective test file using these commands through PHP.
But strangely, where g++ and where javac give this error in the browser when run through PHP:
INFO: Could not find files for the given pattern(s).
Also if I get the outputs of these two commands on the console and then copy that into my script to compile a c++ or java file, it works perfect. But the where command returns the above INFO when run through the PHP script.
I am running the server on localhost using XAMPP. Any idea what is missing?
I am using Php in Linux Cent OS. I wanted to convert PDF to SWF, So I use SWFTools. SWFTools consists of pdf2swf command, which is executing fine when I use it in command line. But the command is not working when I execute it through php.
Error: command not found
I have found the extensions are up to date.
Anything else is missing in between?
Use the full path.
The path environmental variable will be different when running under PHP, since that will run as another user.