Echo exec not working tesseract - php

I'm working on using tesseract with PHP and this is my first time using such things as exec.
/usr/local/bin/tesseract /images/hello.png stdout works perfectly via SSH but nothing happens when I try and run this via PHP;
echo exec('/usr/local/bin/tesseract images/hello.png result');
But if I try;
echo exec('/usr/local/bin/tesseract images/hello.png result 2>&1');
Then the page writes Tesseract Open Source OCR Engine v3.03 with Leptonica So I feel like I must close.
Any ideas?

Got it working using the following
exec('/usr/local/bin/tesseract /images/hello.png stdout', $msg);
print_r($msg);

http://php.net/manual/en/function.exec.php
Return Values
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
To get the output of the executed command, be sure to set and use the output parameter.

Related

Call to wget from PHP's shell_exec not working

I'm trying to run a PHP script locally that scrapes Google with wget and dumps the HTML into temp.html.
Running this command from the terminal works fine:
wget -O temp.html http://www.google.ca
Running this command from PHP also works fine (so it's not a permissions issue):
shell_exec('touch temp.html');
But running this from PHP does not work (does not create temp.html):
shell_exec('wget -O temp.html http://www.google.ca');
Any suggestions? Wrapping that last command in a var_dump() outputs null.
Thanks!
According to man wget, using wget -O temp.html http://google.com takes all documents, concatenates them and prints everything in temp.html, without producing any stdout so PHP's shell_exec doesn't return anything (null).
The content of the scraped webpage should be present in temp.html, but shell_exec("wget ...") does not return anything, as not output is produced.
As you mentioned the webpage you are trying to scrape does not work, maybe they implemented some sort of bot-protection preventing exactly what you are trying.
Edit: You may use - to print everything to stdout instead. So try using shell_exec("wget -O - https://google.com"); should return the content of the requested page to your PHP script.
The simplest solution is to provide full path to the wget binary as it seems the user that runs your script does ot have the same $PATH as you.
How about using file_put_contents & file_get_contents instead? This should work without having to worry about wget.
<?php
$filename = 'temp.html';
$address = 'http://www.google.ca';
file_put_contents($filename,file_get_contents($address));
?>

php exec returns less results than entering into command line directly

I have an exec command that is behaving differently than the same command given to linux through Penguinet.
$res = exec('cd /mnt/mydirectory/; zcat log_file.gz');
echo $res
When putting the commands directly into the command line, I see about 100 entries in the log file. However when I access the PHP page that has the exec() command, I see only 1. And it is formatted correctly. Why does PHP show me only one result? How can I make it show the entire contents of the file?
EDIT:
Seems this is only returning only the last line. How can I change that?
try this:
exec('cd /mnt/mydirectory/; zcat log_file.gz', $res);
print_r($res);

exec in php is working inappropriately

I am willing to execute a shill command through PHP but i faced that the command is not executing , here is the command:
exec('/cutycapt/CutyCapt --url="' . $source . '" --out="/home/user/NetBeansProjects/PhpProject1/htmlImage/example.png"');
i tried as testing to execute the following :
echo exec(' ls /cutycapt/');//print_r is the same
only one file returned while this command returned them all
echo system(' ls /cutycapt/');
i tried to use the "system" method instead of exec in the first command and the result was the same
what could affect the command so it wan't execute ?
update
the case i'm talking bout the the first command work whether i run it in the terminal or i run the PHP script in terminal too but when i run it from the browser (the php script )it doesn't work !!
Look into manual - http://de3.php.net/manual/en/function.exec.php
exec and system returns "The last line from the result of the command"
In case of system and exec the last line from the result of the command gets returned.
If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
I had the same problem working with external commands in php. The problem was related to file permissions. I was using "vchiq" library and the error was "* failed to open vchiq instance". This page might work for you.

Executing SASS script from PHP and getting output

I have this PHP script (test.php):
<?php
$cmd = "/usr/bin/sass --watch file1.scss";
system($cmd);
?>
Now I call my PHP script from CLI this way:
/usr/bin/php test.php
And I get no output (it should print SASS is watching for changes).
If I call the SASS command directly from the shell, it outputs correctly.
Why?
Info: I'm using the PHP 5.3.6 version on OS X Lion
Edit: Please, note that this command watches for changes, it seems to behave differently to a regular command.
Edit2: The command works, it compiles correctly. The only thing lacking is the output (I want to debug and see errors :)
Some command line utilities like sass, manipulate the output pipe in some way that PHP can't use.
So, in this particular case, there is no solution.
system() returns a string. Just echo it.
According to http://se.php.net/system you need to pass in a second argument to system() and the return value of the command will be set in that variable:
<?php
system($command, $return);
echo $return;

How to execute system() without any output

I have a basic php script that calls system("netstat -l") and the reads what services are online. I got it all working exept that system() sends the whole return to the client... So my question is how do i run system() whiteout having it sending the command output to the client?
Im running this on ubuntu server.
You can do:
$output = shell_exec('netstat -l');
$output will now contain the output of the command.
shell_exec
Use shell_exec(). It will return the output of the command, instead of printing it like system().

Categories