![]() |
#1 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Oct 2008
Device: none
|
Calibre Command Line usage with PHP
Hello!!
I am trying to convert HTML files to LRF, EPUB or other formats using calibre's "html2lrf" and "html2epub" functions. Everything works absolutely fine when I use the normal windows command line interface. But when I use the exact same command with PHP and "shell_exec" or "exec" absolutely nothing happens. No error message, but no output either. The funny thing is - until now I used "CalibreForLRF" for that, and for some reason, that EXE file with that installation works fine. ![]() Has anyone else experienced such problems and has a solution for this? Or is there a thread about that problem already? Many thanks in advance! ![]() Artoros |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,279
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
what OS are you on?
|
![]() |
![]() |
![]() |
#3 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,832
Karma: 11844413
Join Date: Jan 2007
Location: Tampa, FL USA
Device: Kindle Touch
|
Quote:
Need more input. BOb |
|
![]() |
![]() |
![]() |
#4 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Oct 2008
Device: none
|
Thanks for the quick answers - you are right...more input..here it comes :-)
I am using a Windows 2003 server with PHP 5.2.5. No Apache or whatever only the windows server. As I wrote, it is strange: I have now both calibre and calibreForLRF installed and when I use the latter with PHP (shell_exec) it works and creates the LRF file properly: C:\[pathtocalibre]\calibreForLRF\html2lrf.exe -t "Booktitle" -a "Dwayne Dibbley" -o [pathtolrf]/thebook.lrf [pathtohtml]/thebook.htm --cover [pathtocover]/thecover.jpg Using the latest calibre version (0.4.99) with the SAME command in PHP, it doesn't work (but it does work when I paste the command into the windows command line interface): C:\[pathtocalibre]\calibre\html2lrf.exe -t "Booktitle" -a "Dwayne Dibbley" -o [pathtolrf]/thebook.lrf [pathtohtml]/thebook.htm --cover [pathtocover]/thecover.jpg (The only difference is the path to calibre ("calibreForLRF" and "calibre") Or to make it short: CalibreForLRF - Windows command line: ok CalibreForLRF - PHP: ok Calibre - Windows command line: ok Calibre - PHP: NOT ok ![]() I thought, that maybe the two installations interfere somehow, but when I have only calibre installed, it doesn't do anything either. I even tried to create a windows BAT-file and call calibre via PHP and that file, but that doesn't work either. Thanks again for any help! Before you ask: I am trying to use the new calibire, because I would like to create EPUB files as well. If it would be only for the LRFs, of course, I just would still use the old calibreForLRF ![]() |
![]() |
![]() |
![]() |
#5 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,279
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
make sure that the calibre installation directory is in the path variable of the the environment in which PHP is executing calibre
|
![]() |
![]() |
![]() |
#6 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Oct 2008
Device: none
|
Hi!
Thanks for the quick answer!! Hm, what do you mean exactly? The path is already in the windows environmental variable "Path". I guess calibre adds this path automatically during the installation process, right? Or do you mean something else? Is there any PHP-setting? I checked the whole php.ini, but didn't find anything that would help. By the way - talking about php.ini: Safe mode is off! (hm, maybe I should change that some other time ![]() As I wrote: It wouldn't be so strange, if the old CalibreForLRF wouldn't work either (along with some other EXE-programs I am using with PHP on the same server). |
![]() |
![]() |
![]() |
#7 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,279
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
the php function you use to launch an external executable, it will be setting environment variables and for security reasons it probably strips the calibre installation directory from the path
|
![]() |
![]() |
![]() |
#8 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Oct 2008
Device: none
|
![]() I checked now the shell_exec- and exec-Command description at php.net. Unfortunatley there is nothing about stripping the path for security reason. I tried now even giving total read/write/execute permission for the IUSR for - ALL calibre files - system32/cmd.exe - SysWOW64/cmd.exe But without any success ![]() As I wrote: I wouldn't wonder, if all the other EXE-programs wouldn't work either. But they do. Why should PHP act differently for the calibre-EXE files? Ok, I now found a way, how it (somehow) works - at least theoretically: I did a batch file with the convert-command in it and called this one using exec("c:\\windows\\system32\\cmd.exe /c c:\\test.bat"); Now THAT acutally works. Ok, now all I have to do is to transfer the name of the converted file into the batch file somehow and then call the cmd to call the batch file to call the calibre-function ![]() Hm, ok, if anyone knows a better way, I would be happy to know. But maybe at least I can do the conversion that way. "If it's dumb, but it works - it ain't dumb" ![]() |
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,832
Karma: 11844413
Join Date: Jan 2007
Location: Tampa, FL USA
Device: Kindle Touch
|
Quote:
BOb |
|
![]() |
![]() |
![]() |
#10 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Oct 2008
Device: none
|
Quote:
Here, that is the test code: <? $toexe = "C:\\calibre\\html2lrf.exe -t test -a test -o C:\\documents\\155.lrf C:\\documents\\155.htm"; $output = array(); exec($toexe, &$output, &$num); echo nl2br(print_r($output,true))."<br />".$num;?> ?> And the output: Array ( ) 255 $output is totally empty. The funny thing: When I mispell the command name, let's say "html3lrf.exe" then I don't get any output either, but $num changes from 255 to 1. Any ideas left? :-) |
|
![]() |
![]() |
![]() |
#11 |
Connoisseur
![]() Posts: 76
Karma: 22
Join Date: Mar 2008
Location: uk
Device: Sony PRS505
|
try a simple php page that just runs the command 'c:\windows\cmd.exe /c set' and see what paths and stuff are returned.
|
![]() |
![]() |
![]() |
#12 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jun 2010
Device: none
|
command line problem with php shell_exec
I'm using ubuntu server 10.04
I need to convert pdf to txt. so hardly installed calibre not windows ;-) But I should use it on linux.. then I have a new problem like below when I'm using shell_exec() with PHP. ================================================== ===== Traceback (most recent call last): File "/usr/bin/ebook-convert", line 18, in <module> from calibre.ebooks.conversion.cli import main File "/usr/lib/calibre/calibre/__init__.py", line 14, in <module> from calibre.startup import plugins, winutil, winutilerror File "/usr/lib/calibre/calibre/startup.py", line 51, in <module> set_translators() File "/usr/lib/calibre/calibre/utils/localization.py", line 66, in set_translators lang = get_lang() File "/usr/lib/calibre/calibre/utils/localization.py", line 27, in get_lang from calibre.utils.config import prefs File "/usr/lib/calibre/calibre/utils/config.py", line 698, in <module> tweaks = read_tweaks() File "/usr/lib/calibre/calibre/utils/config.py", line 681, in read_tweaks make_config_dir() File "/usr/lib/calibre/calibre/utils/config.py", line 40, in make_config_dir os.makedirs(plugin_dir, mode=CONFIG_DIR_MODE) File "/usr/lib/python2.6/os.py", line 150, in makedirs makedirs(head, mode) File "/usr/lib/python2.6/os.py", line 150, in makedirs makedirs(head, mode) File "/usr/lib/python2.6/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/root/.config' ================================================== ====== How can I use it with PHP shell_exec? |
![]() |
![]() |
![]() |
#13 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,279
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
set the environment variable CALIBRE_CONFIG_DIRECTORY
|
![]() |
![]() |
![]() |
#14 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jun 2010
Device: none
|
Dear, kovidgoyal
Thanks for your response. Unfortunately, I'm a newbie so exactly don't know how to set enviornment of it. plz show me an example of CALIBRE_CONFIG_DIRECTORY? Thank you. |
![]() |
![]() |
![]() |
Tags |
calibre, command line, php |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Old Thread] Calibre Command line and .bat file | stratman | Calibre | 15 | 01-10-2012 05:38 PM |
Autotagging with Calibre (command line) | erion | Calibre | 11 | 08-28-2010 01:33 PM |
Specify liberary path in command line when launching calibre | rollercoaster | Calibre | 2 | 03-04-2010 12:08 AM |
Calibre Command Line Interface TOC | bcolflesh | Calibre | 3 | 02-04-2010 04:09 PM |
calibre command line utilities and calibre defaults | astrodad | Calibre | 2 | 08-07-2008 03:27 PM |