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.
Related
I have this code, as part of a php script:
exec("php runScript.php --task_id {$taskId} 2>&1 ", $scriptOutput);
Where scriptoutput returns: 'php' is not recognized as an internal or external command.
I have php in my systemvariables and when I run
php runScript.php --task_id 1
on the commandline it works without problems and i can use the php command for other things such as php composer.phar install.
But when my php script arrives at the rule with the exec code, it returns that php isnt recognized. The script works on Ubuntu, but not locally on my Windows environment. So perhaps it's a Windows issue.
I read a lot about environmentvariables but if that was the case i wasn't able to use php in the command line. Now it's only not working via exec.
I hope someone can help me with this.
Scanline is a simple command line utility used for scanning documents from a twain scanner. http://blog.scottkleper.com/scanline-command-line-scanner-for-mac/
I am trying to use Scanline through a PHP script using shell_exec(); the same way that I would use it directly from the terminal in MacOS.
When I run Scanline directly from the command line, it detects all the attached scanners and prints them out ./scanline -list
When I run Scanline using shell_exec(), it does not detect any devices.
So far, I have changed the apache user to my local user, and have added the local user to the sudoers file. If I run 'whoami' in shell_exec() it is the same result as if I run it in command line.
I have printed the environment using printenv in command line, and have setup all of the same variables in my php script before executing shell_exec() using putenv(); If I run shell_exec('printenv 2>&1'), it is the exact same environment as when I run printenv in command line.
All the permissions are correct and allow access, and scanline runs when executed through shell_exec() without error (I checked apache's error logs, as well as put a error_reporting(E_ALL); in the top of the PHP file to printout any issues along the way). The only difference in how the program is executed is that in command line the devices are detected, and run through shell_exec(), no devices are found.
Any ideas as to what else I could be missing between command line and using shell_exec() ?
I also tried using system(), exec(), and shell_exec() interchangeably with the same result.
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 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 using PHP to ssh into a main computer and run a command. My code is posted below but I'm stuck having the following issue:
When I run this command from the Ubuntu command line it works flawlessly. However when I try and run it via the web page I believe the ssh commands are not running. Not sure if I am running into issues with permissions, or if I am running into issues with my actually ssh command in php. Any help would be appreciated.
$cmd = "ssh name#ip 'echo hello'";
$var = shell_exec($cmd);
echo $var;
Rather than using shell_exec (which may be disabled for security reasons), look into using libssh2.
Reference: http://php.net/manual/en/book.ssh2.php
My guess would be that the user that the webserver runs as doesn't have your private key file in its ~/.ssh directory.