Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Related Tools

Notices

Reply
 
Thread Tools Search this Thread
Old 10-23-2008, 10:40 AM   #1
artoros
Junior Member
artoros began at the beginning.
 
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. But I can only do LRF files with that one, of course.

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
artoros is offline   Reply With Quote
Old 10-23-2008, 11:10 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,744
Karma: 22446736
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
what OS are you on?
kovidgoyal is offline   Reply With Quote
Advert
Old 10-23-2008, 11:17 AM   #3
pilotbob
Grand Sorcerer
pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.
 
pilotbob's Avatar
 
Posts: 19,832
Karma: 11844413
Join Date: Jan 2007
Location: Tampa, FL USA
Device: Kindle Touch
Quote:
Originally Posted by artoros View Post
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.
Are you executing the script only, or are you passing the python interperter in your command? Are you using Apache? Do you have mod_python installed? Are you using a shebang in your script?

Need more input.

BOb
pilotbob is offline   Reply With Quote
Old 10-24-2008, 01:55 AM   #4
artoros
Junior Member
artoros began at the beginning.
 
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
artoros is offline   Reply With Quote
Old 10-24-2008, 02:08 AM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,744
Karma: 22446736
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
kovidgoyal is offline   Reply With Quote
Advert
Old 10-24-2008, 02:36 AM   #6
artoros
Junior Member
artoros began at the beginning.
 
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).
artoros is offline   Reply With Quote
Old 10-24-2008, 02:38 AM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,744
Karma: 22446736
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
kovidgoyal is offline   Reply With Quote
Old 10-24-2008, 05:07 AM   #8
artoros
Junior Member
artoros began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Oct 2008
Device: none
I guess maybe I am just too stupid for this.

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"

artoros is offline   Reply With Quote
Old 10-24-2008, 02:11 PM   #9
pilotbob
Grand Sorcerer
pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.
 
pilotbob's Avatar
 
Posts: 19,832
Karma: 11844413
Join Date: Jan 2007
Location: Tampa, FL USA
Device: Kindle Touch
Quote:
Originally Posted by artoros View Post
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
What is the error? You should be able to pass a second parameter to the exec() function to get the results from the command line.

BOb
pilotbob is offline   Reply With Quote
Old 10-27-2008, 08:36 AM   #10
artoros
Junior Member
artoros began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Oct 2008
Device: none
Quote:
Originally Posted by pilotbob View Post
What is the error? You should be able to pass a second parameter to the exec() function to get the results from the command line.

BOb
No error, nothing. Besides a 255 as return value - whatever that means.
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? :-)
artoros is offline   Reply With Quote
Old 10-30-2008, 02:57 PM   #11
Megatron-UK
Connoisseur
Megatron-UK began at the beginning.
 
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.
Megatron-UK is offline   Reply With Quote
Old 07-01-2010, 07:41 AM   #12
ryanlee
Junior Member
ryanlee began at the beginning.
 
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?
ryanlee is offline   Reply With Quote
Old 07-01-2010, 09:18 AM   #13
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,744
Karma: 22446736
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
set the environment variable CALIBRE_CONFIG_DIRECTORY
kovidgoyal is offline   Reply With Quote
Old 07-01-2010, 09:57 AM   #14
ryanlee
Junior Member
ryanlee began at the beginning.
 
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.
ryanlee is offline   Reply With Quote
Reply

Tags
calibre, command line, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 04:56 AM.


MobileRead.com is a privately owned, operated and funded community.