I'm building a website that needs some ressources from a software in windows. So, I need to run windows' shell from notepad++ using php. Are there any php scripts to execute commands from windows' shell?
You can use the PHP function exec() - do note that there are some bugs with it (If a script (with the exec command) is loaded more than once by the same user at the same time the server will freeze.)
A solution for this is found in the PHP manual:
<?php
session_write_close();
exec($cmd);
session_start();
?>
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 am writing a PHP script to fetch some values from XML. Now, I want to pass those values to Matlab. Is it possible to run matlab code in PHP script? If yes, do I need to have matlab installed in /var/www/html (I'm using Ubuntu)?
This is how such a command would look in Windows:
<?php
$command='matlab -nodesktop -r "run emailToSpeech.m";';
exec ( $command );
?>
In this example, the .m script has to reside in the same directory as your PHP script, but MATLAB itself does not. (And you could always change directories if you prefer to do it that way.) I would expect Ubuntu to work similarly, although I haven't had a chance to try it yet.
The question linked below has a fuller discussion in case you want to explore further:
running MATLAB code from php
We connect to our server using php, I generally run shell scripts,I want to convert those scripts into php scripts.So how to know whether i can run php scripts on my server or not.So how to run these php scripts on my putty connected server?
Ensure the PHP command line program is installed.
Run php /path/to/your/script.php
You can use the PHP CLI to run the script.
You can write like php filename.php.
If the php don't work then check for the actual path of the php.
It should be like /usr/bin/php .
I have a php webpage located on Webserver1, which is from Host1.
I also have a bash script located in Gameserver1 which is from Host2.
Is there any way to send a command from Webserver1 to Gameserver1 to execute the bash file? The webpage and file are on different VPSs. Both are running Debian 7.
The script is literally one line, to execute a java command via a screen, so the server can start if a player notices it's down. The command's available already so it doesn't need to be a secure way of hiding what the command is.
There are 2 ways I can think of. either create a bash file in Webserver1 that connects through ssh and executes the bash script you need on Gameserver1. then run it through php with exec() command.
Or you can create a php file in Gameserver1 that uses exec() to execute the bash script you need on Gameserver1 and call it using file_get_contents() on Webserver1, which is not that secure since anyone can call that file and run your script.
On my debian i run xampp. I want to execute a python script using php shell_exec.
This is my php code:
shell_exec("/opt/lampp/htdocs/news/hello.py 2>1 &");
When i run it from the browser i get this error:
/usr/bin/python: /opt/lampp/lib/libz.so.1: no version information available (required by /usr/bin/python)
If i run it from the terminal window using this: php /opt/lampp/htdocs/page/index.php it works without any problems.
So any ideas how can i make it work from the browser?
Thanks
I'm guessing xampp comes with it's own libraries instead of using the system libraries, and that probably means it's setting LD_LIBRARY_PATH to it's local library directory.
This will also cause other programs started from php to use this libraries, which they may not be compatible with.
To veryfy that, try system("env");, that sould show you all the exported environment variables. If LD_LIBRARY_PATH is set, use:
shell_exec("LD_LIBRARY_PATH= /opt/lampp/htdocs/news/hello.py 2>1 &");
That unsets it before running the python script.