![]() |
#1 |
Junior Member
![]() 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. |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,553
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.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,201
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
![]() |
![]() |
![]() |
#4 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
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. |
|
![]() |
![]() |
![]() |
#7 |
Junior Member
![]() 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 :-) |
![]() |
![]() |
![]() |
#8 |
Junior Member
![]() 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! |
![]() |
![]() |
![]() |
#9 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: May 2011
Device: nook, Nokia N800 with FBreader
|
![]()
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, forebook-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 .batebook-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. ![]() ![]() ![]() --------------------------- 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.). ![]() 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. |
![]() |
![]() |
![]() |
#10 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,201
Karma: 27110894
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]]) Code:
calibre-debug -e myscript.py input_file.epub output_file.epub I'm sure you can figure out the rest. |
![]() |
![]() |
![]() |
#11 |
Junior Member
![]() 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. ![]() ![]() |
![]() |
![]() |
![]() |
#12 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,201
Karma: 27110894
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. |
![]() |
![]() |
![]() |
#13 |
Junior Member
![]() 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.) |
![]() |
![]() |
![]() |
#14 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
|
|
![]() |
![]() |
![]() |
#15 |
Junior Member
![]() 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% |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |