I have downloaded Tesseract OCR, installed it on windows and set its path variable and test it as well.
https://github.com/thiagoalessio/tesseract-ocr-for-php
I have downloaded its php script too and did some basic testing.
echo $this->buildTesseractCommand();
exec(trim($this->buildTesseractCommand()));
The command
echo tesseract C:\xampp\htdocs\OCR\test\images\hello.png C:\xampp\htdocs\OCR\test\temp\29847.txt
where hello.png is file to read characters from and 29847.txt is random file generated from cmd in which output is stored. although the same command is working directly through cmd.
But sadly the command is not working through php and no .txt file is generated , but when I paste the same in my command prompt, it works and file is generated.
I have tried system(), exec() and passthru() functions to run command but its not working in any :(
Any idea how to run it or any alternatives ?
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.
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 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?
how can I execute command wkhtmltopdf http://google.com /tmp/test.pdf from server ie http://localhost/test.php, when I do it from command line it works. I tried system() and exec() functions but did not work. When I use system('touch /tmp/test') file is created. What stops wkhtmltopdf? Is it php, apache?
Make sure that the user the script is running as knows where wkhtmltopdf bin is.
You can find out where it is with the which command.
which wkhtmltopdf
Also you can get the return status of a command by setting a variable equal to it
e.g.
$last_line = system('ls');
echo $last_line