I am trying to compile python code using shell_exec(), or exec().
The code I am trying:
$output = shell_exec("C:/Users/AS/AppData/Local/Microsoft/WindowsApps/python.exe C:/wamp64/www/project/app/code.py 2>&1");
echo $output;
when I execute the command in shell or in the command line It works fine, However using php and (Apache sever) I get The system cannot execute the specified program. Though I can successfully execute different commands such as mkdir,
but if I try any command with .exe extension in my windows 11, I get the the same error as above.
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.
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 using Pageres to capture a Highcharts chart. I have a PHP script that takes in an argument to generate the proper URL and file name for the pageres command. When I go to use PHP's exec command, it fires off a bunch of pageres commands and never actually completes the pageres command. The pageres command works perfectly from the command line though.
Snippet of my PHP code:
$cmd = "pageres http://localurl/wriphp/visGraph.php?port=".$port." 1100x200 --filename ".$port;
exec($cmd);
Why does the php exec call run out of control?
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?
am using ffmpeg in one of my sites with PHP , i convert files using the php exec function , actually it did me some headache trying to figure out WHEN this ffmpeg completes the file conversion after executing the exec command :( is there anyway to do that ?
Thanks
From what I've found, the exec function blocks until the ffmpeg conversion is complete.
For example, you can run ffmpeg like this in your PHP script:
exec($encode, $output);
(Where $encode is the ffmpeg command as a string, and $output is an array of each line of output from ffmpeg.)
For me, this exec command blocks my PHP script from continuing until ffmpeg conversion is complete, at which point my PHP script continues on, which seems to be how it is described in the PHP manual:
http://php.net/manual/en/function.exec.php
So, you can tell when exec is complete by following the exec command with another PHP command on the next line in your script that notifies you conversion is complete, or updates a database, or what-have-you.
FYI, I believe that pushing the exec command "into the background" means running the exec command but having the PHP script continue on simultaneously (i.e. asynchronously). For running the exec command in the background, Google "PHP background exec" or "php multi-process", such as:
http://www.php.net/manual/en/ref.exec.php#80241
http://www.sitecrafting.com/blog/to-run-php-code-in/