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

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 03-01-2010, 06:27 PM   #1
stratman
Junior Member
stratman began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Jan 2010
Device: nook
[Old Thread] Calibre Command line and .bat file

I'm using Win XP and having problems executing multiple command lines in a .bat file. Each line can be copied and executed individually in the command prompt, but when I collect them into a single file, the batch dies after successfully completing the first conversion. The paths are mapped correctly, otherwise it wouldn’t complete the first command.

The command line looks like this:

ebook-convert "Z:\directory\file1.pdb" "Y:\directory\file1.epub" --no-default-epub-cover --line-height=16 --base-font-size=12 --margin-top=15 --margin-left=15 --margin-right=15 --margin-bottom=10 --remove-paragraph-spacing --use-auto-toc
ebook-convert "Z:\ directory\file2.pdb" "Y:\ directory\file1.epub" --no-default-epub-cover --line-height=16 --base-font-size=12 --margin-top=15 --margin-left=15 --margin-right=15 --margin-bottom=10 --remove-paragraph-spacing --use-auto-toc

etc.
stratman is offline   Reply With Quote
Old 03-01-2010, 06:37 PM   #2
itimpi
Wizard
itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.itimpi ought to be getting tired of karma fortunes by now.
 
Posts: 4,552
Karma: 950151
Join Date: Nov 2008
Device: Sony PRS-950, iphone/ipad (Marvin/iBooks/QuickReader)
I believe this is a known issue. Not sure what makes it happen though.
itimpi is offline   Reply With Quote
Advert
Old 03-01-2010, 09:11 PM   #3
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,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
http://bugs.calibre-ebook.com/ticket/3923
kovidgoyal is offline   Reply With Quote
Old 03-01-2010, 10:06 PM   #4
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by stratman View Post
I'm using Win XP and having problems executing multiple command lines in a .bat file. Each line can be copied and executed individually in the command prompt, but when I collect them into a single file, the batch dies after successfully completing the first conversion.
It's a known issue. A workaround I found is to precede each line with "start" in your batch file. That spawns a separate command com for each line, and each dies with its line, but only after completion of the line.
Starson17 is offline   Reply With Quote
Old 03-02-2010, 12:19 AM   #5
pepak
Guru
pepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura aboutpepak has a spectacular aura about
 
Posts: 610
Karma: 4150
Join Date: Mar 2008
Device: Sony Reader PRS-T3, Kobo Libra H2O
My guess would be you are not running ebook-convert directly but through a BAT file. That would result in the behavior you describe.

Even if it is not the case, the fix that would have worked with BAT files will likely work for your case: Just prefix your calls to ebook-convert with either call or cmd /c. Unlike the start fix, this will NOT start a new console window for each ebook-convert, and it will run te commands sequentially rather than all at once.
pepak is offline   Reply With Quote
Advert
Old 03-02-2010, 06:27 AM   #6
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by pepak View Post
Just prefix your calls to ebook-convert with either call or cmd /c. Unlike the start fix, this will NOT start a new console window for each ebook-convert, and it will run te commands sequentially rather than all at once.
I tried both call and cmd /c when trying to work around problems with calibredb and batch files. It's true they don't spawn another cmd session, but they also didn't work. Calibredb crashed the first session every time, so the batch would never complete. I don't know if ebook-convert is different, but, at least for calibredb running in a batch file, you need to use start, or the Powershell workaround.

If your batch needs sequential operation, then you need to be trickier or use Powershell.

Last edited by Starson17; 03-02-2010 at 06:30 AM.
Starson17 is offline   Reply With Quote
Old 03-15-2011, 03:34 PM   #7
reading
Junior Member
reading began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Mar 2011
Device: Kindle
Just found this and thought I would add a comment.

One of the issues you encounter with using "start" is redirecting output to a text file
start "" /WAIT calibredb.exe .... >out.txt

This does not work as the output redirection doesn't get passed.
The normal way to fix this is to escape the > with ^>

start "" /WAIT calibredb.exe .... ^>out.txt

But for some reason this does not work with calibre, the process works but calibre doesn't seem to understand the command line that was passed

This next solution works, but I have no idea why :-(, putting additional ^'s breaks it

start "" /WAIT cmd.exe /c ""calibredb.exe^" .... ^>tmp1.txt"

For a solution I can understand, this works ...

echo @%calibredb% ....>tmp.cmd
start "Calibre" /WAIT /MIN cmd.exe /c tmp.cmd ^>tmp.txt

Hope this helps someone :-)
reading is offline   Reply With Quote
Old 03-15-2011, 03:55 PM   #8
reading
Junior Member
reading began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Mar 2011
Device: Kindle
ooo, this trick seems to work also

start "Calibre" /WAIT /MIN cmd /c (calibredb.exe ... )^>tmp.txt

quotes seem to work fine with the (), for example:-

start "Calibre" /WAIT /MIN cmd /c ("c:\Program Files\Calibre2\calibredb.exe" list --separator , -w 255 -f authors,cover -s "title:Zero Game")^>tmp.txt

enjoy!
reading is offline   Reply With Quote
Old 05-05-2011, 11:47 PM   #9
Little Frank
Junior Member
Little Frank began at the beginning.
 
Posts: 6
Karma: 10
Join Date: May 2011
Device: nook, Nokia N800 with FBreader
Cool

First, there is a limit of 127 characters to any MS-DOS command line; more then 127 characters and MS-DOS truncates the line without a warning. This is not a Calibre bug, but intrinsic to MS-DOS, and Microsoft has declined changing it for over 20 years. See
http://support.microsoft.com/kb/69563
(IBM field engineers are trained to say “that isn’t a bug, that’s part of a feature for our other customers” when they are backed into a corner.)
I have launched
ebook-meta ThisBook.epub --to-opf file.opf
Then edited the .opf file, for
ebook-meta ThisBook.epub --from-opf file.opf --other-meta
but if there is an equivalent way of loading the ebook-convert non - meta data, I haven’t found it.
A feature of Windows is that it tries to launch all the Windows programs it can find in a .BAT file at one time. Helpful if you’re trying to get 2 spreadsheets and 3 documents going at once; but irritating for sequential processing. What I have found myself doing in a .bat is:
copy "Eusebeus Church History.htm" in.htm
del *.epub
ebook-convert in.htm w.epub --output-profile nook --level1-toc //h:h2 --level2-toc //h:h4 --max-toc-links 0 --chapter /
This is barely under the length limit, but I get all the TOC stuff on one line. There is no space remaining on the line for a pause technique. Then I hand launch a second .bat
ebook-convert w.epub o.epub --output-profile nook --smarten-punctuation --change-justification left --pretty-print
in a second .bat file, this does all the “cosmetic treatment.”
Then a third batch file I hand launch is
ebook-meta o.epub --cover Eu.jpg --author-sort "Eusebius of Caesarea"
which adds the meta data that it can’t find in the HTML.
Oh yeah; one more batch file. Number four.
start "" /w "calibredb.exe" add -d o.epub
start "" /w "ebook-viewer.exe" o.epub
Lets me see the results, and places it in the DB.
If you name the batch file sequentially, conv1.bat conv2.bat conv3.bat conv4.bat; well I’ve got decades of COBOL experience, so I’m brain damaged to the point where it seems acceptable. For the sake of the rest of humanity, and to bypass two MS-DOS/Windows bugs at once, it would be nice if there was one additional option:
---------------------------
ebook-convert in.htm o.epub --command-line misccmds.txt
---------------------------
where misccmds.txt would contain all the familiar calibre line commands; either all on one line, or preferably, it being possible to spread out the line commands with their parameters over more then one line. (.txt extension preferable so it would open automatically with Notepad/VIM/etc.).
Thank you for your attention to this matter; and the excelent product. Usually doing everything through the GUI interface is good enough for me, and I'm done in two minutes, but once in a while . . .
P.S. I have done enough stuff in Linux to be able to see how it would be helpful to combine different misccmds.txt files with cp, as with MS-DOS copy, since you might want to combine preferred formatting, (second ebook-convert above) with book specific meta-data.
Little Frank is offline   Reply With Quote
Old 05-06-2011, 12:32 AM   #10
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,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You rather than giving yourself a hernia jumping through microsoft hoops, why dont you just use a decent script language instead of BAT. You can even do it with calibre itself for example:

Create a .py file called myscript.py
Code:
import subprocess, sys

# Command line arguments ar in sys.argv
print 'Command line arguments', sys.argv

subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2]])
subprocess.check_call(['ebook-viewer', sys.argv[2]])
Now run this script with

Code:
calibre-debug -e myscript.py input_file.epub output_file.epub
This will run ebook-convert for you and open the result in the viewer.

I'm sure you can figure out the rest.
kovidgoyal is offline   Reply With Quote
Old 05-07-2011, 02:21 AM   #11
Little Frank
Junior Member
Little Frank began at the beginning.
 
Posts: 6
Karma: 10
Join Date: May 2011
Device: nook, Nokia N800 with FBreader
Once more, please.

This
subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2], --cover eu.jpg])
blows up,
this
subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2], "--cover eu.jpg"])
died
this
Ptotal = " --cover eu.jpg "
subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2], Ptotal])
produced the default cover,
this
subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2] + " --cover eu.jpg"])
died, and I was laughing before I tried it;
subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2], """ --cover eu.jpg"""])
generated the default cover.
OK, I give, what does replacing the cover look like?
Little Frank is offline   Reply With Quote
Old 05-07-2011, 11:26 AM   #12
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,778
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2], '--cover', 'eu.jpg'])

constant arguments must be in quotes, variables not in quotes.
kovidgoyal is offline   Reply With Quote
Old 05-07-2011, 04:40 PM   #13
Little Frank
Junior Member
Little Frank began at the beginning.
 
Posts: 6
Karma: 10
Join Date: May 2011
Device: nook, Nokia N800 with FBreader
Thanks!


Thank YOU! This works!
Ptotal = ['--output-profile ', 'nook ', \
'--level1-toc ', '//h:h2 ', \
'--level2-toc ', '//h:h4 ', \
'--max-toc-links ', '0 ', \
'--smarten-punctuation ', \
'--change-justification ', 'left ', \
'--pretty-print ', \
'--preserve-cover-aspect-ratio ', \
'--enable-heuristics ', \
'--rating ', '4 ', \
'--author-sort ', 'Eusebius_of_Caesarea ', \
'--cover ', 'eu.jpg']

subprocess.check_call(['ebook-convert', sys.argv[1], sys.argv[2], Ptotal])


(Except for the 'rating' and 'author-sort'; I can work around those)
I love Calibre!
(And I indent my code; don't know what happened with the example I pasted in here.)
Little Frank is offline   Reply With Quote
Old 05-07-2011, 04:52 PM   #14
Manichean
Wizard
Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Manichean's Avatar
 
Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
Quote:
Originally Posted by Little Frank View Post
(And I indent my code; don't know what happened with the example I pasted in here.)
Use code tags. In the advanced edit dialog, it's the hash sign ('#').
Manichean is offline   Reply With Quote
Old 11-21-2011, 12:34 AM   #15
Ponderz
Junior Member
Ponderz began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Nov 2011
Device: Sony Clie SJ20
My conversion script. Put into Sendto folder.

I got a sendto batch file that is working for me. Hope someone can use it.

rem Get all parameter into variable
rem Will get only 15 parameters.
rem Out file to same directory as source.

if exist M:\ap\Calibre2\ebook-convert.exe set calibre=M:\ap\Calibre2\ebook-convert.exe
if exist d:\ap\Calibre2\ebook-convert.exe set calibre=d:\ap\Calibre2\ebook-convert.exe

set count=0


IF NOT (%1)==() (
SET p1=%1
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%2)==() (
SET p2=%2
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%3)==() (
SET p3=%3
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%4)==() (
SET p4=%4
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%5)==() (
SET p5=%5
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%6)==() (
SET p6=%6
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%7)==() (
SET p7=%7
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%8)==() (
SET p8=%8
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%9)==() (
SET p9=%9
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%10)==() (
SET p10=%10
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%11)==() (
SET p11=%11
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%12)==() (
SET p12=%12
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%13)==() (
SET p13=%13
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%14)==() (
SET p14=%14
) ELSE (
set /a count+=1 && goto begin
)
IF NOT (%15)==() (
SET p15=%15
) ELSE (
set /a count+=1 && goto begin

:begin

echo count:%count%
echo p1:%p1%
echo p2:%p2%
echo p3:%p3%
echo p4:%p4%
echo p5:%p5%
echo p6:%p6%
echo p7:%p7%
echo p8:%p8%
echo p9:%p9%
echo p10:%p10%
echo p11:%p11%
echo p12:%p12%
echo p13:%p13%
echo p14:%p14%
echo p15:%p15%

IF (%p1%)==() set /a count+=1 && GOTO END
IF NOT (%p1%)==() start /wait /min %calibre% %p1% %p1%.epub --no-default-epub-cover --use-auto-toc

IF (%p2%)==() set /a count+=1 && GOTO END
IF NOT (%p2%)==() start /wait /min %calibre% %p2% %p2%.epub --no-default-epub-cover --use-auto-toc

IF (%p3%)==() set /a count+=1 && GOTO END
IF NOT (%p3%)==() start /wait /min %calibre% %p3% %p3%.epub --no-default-epub-cover --use-auto-toc

IF (%p4%)==() set /a count+=1 && GOTO END
IF NOT (%p4%)==() start /wait /min %calibre% %p4% %p4%.epub --no-default-epub-cover --use-auto-toc

IF (%p5%)==() set /a count+=1 && GOTO END
IF NOT (%p5%)==() start /wait /min %calibre% %p5% %p5%.epub --no-default-epub-cover --use-auto-toc

IF (%p6%)==() set /a count+=1 && GOTO END
IF NOT (%p6%)==() start /wait /min %calibre% %p6% %p6%.epub --no-default-epub-cover --use-auto-toc

IF (%p7%)==() set /a count+=1 && GOTO END
IF NOT (%p7%)==() start /wait /min %calibre% %p7% %p7%.epub --no-default-epub-cover --use-auto-toc

IF (%p8%)==() set /a count+=1 && GOTO END
IF NOT (%p8%)==() start /wait /min %calibre% %p8% %p8%.epub --no-default-epub-cover --use-auto-toc

IF (%p9%)==() set /a count+=1 && GOTO END
IF NOT (%p9%)==() start /wait /min %calibre% %p9% %p9%.epub --no-default-epub-cover --use-auto-toc

IF (%p10%)==() set /a count+=1 && GOTO END
IF NOT (%p10%)==() start /wait /min %calibre% %p10% %p10%.epub --no-default-epub-cover --use-auto-toc

IF (%p11%)==() set /a count+=1 && GOTO END
IF NOT (%p11%)==() start /wait /min %calibre% %p11% %p11%.epub --no-default-epub-cover --use-auto-toc

IF (%p12%)==() set /a count+=1 && GOTO END
IF NOT (%p12%)==() start /wait /min %calibre% %p12% %p12%.epub --no-default-epub-cover --use-auto-toc

IF (%p13%)==() set /a count+=1 && GOTO END
IF NOT (%p13%)==() start /wait /min %calibre% %p13% %p13%.epub --no-default-epub-cover --use-auto-toc

IF (%p14%)==() set /a count+=1 && GOTO END
IF NOT (%p14%)==() start /wait /min %calibre% %p14% %p14%.epub --no-default-epub-cover --use-auto-toc

IF (%p15%)==() set /a count+=1 && GOTO END
IF NOT (%p15%)==() start /wait /min %calibre% %p15% %p15%.epub --no-default-epub-cover --use-auto-toc

:end

echo count:%count%
Ponderz is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to compile Calibre without QT, but still use it's command line tools? rogerx Calibre 11 08-29-2011 02:41 AM
Calibre Command Line Conversion bmwr1200c Calibre 1 08-10-2011 07:04 PM
calibre bat file windows 7 64bit Dopedangel Calibre 8 05-16-2011 03:38 AM
Autotagging with Calibre (command line) erion Calibre 11 08-28-2010 01:33 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 06:44 AM.


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