View Single Post
Old 01-10-2024, 04:56 AM   #1220
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,199
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by nqk View Post
Sorry to have bugged you this much.

But it returns new error
Code:
  File "subprocess.py", line 548, in run
TypeError: Popen.__init__() got an unexpected keyword argument 'DETACHED_PROCESS'
No problem. We are trying to work this out. And I might use this to improve the stock Open With action. The problem is that the action was designed with the assumption that the format would be the last argument, which is not the case in your command.

Anyway, try this:
Code:
import subprocess
import os
from calibre.constants import iswindows, isosx

def run(gui, settings, chain):
    fmt = 'TXTZ'
    db = gui.current_db
    output_dir = 'D:\Temp'
    path_to_binary = 'C:\Program Files\7-Zip\7z.exe'
    clean_env = dict(os.environ)
    kw = {'env': clean_env, 'shell':True, 'capture_output': True}
    if iswindows:
        del clean_env['PATH']
    elif isosx:
        if path_to_binary.lower().endswith(".app"):
            path_to_binary = 'open -a ' + path_to_binary
    else: #Linux
        clean_env['LD_LIBRARY_PATH'] = ''
    for book_id in chain.scope().get_book_ids():
        path_to_format = db.format_abspath(book_id, fmt, index_is_id=True)
        title = db.title(book_id, index_is_id=True)
        if not path_to_format:
            print(f'Book {title} does not have format: {fmt}')
            continue
        cmd = f'"{path_to_binary}" e {path_to_format} -o"{output_dir}" file-to-extract -y'
        result = subprocess.run(cmd, **kw)
        if result.returncode != 0:
            prints(f'Command error: Return code is {result.returncode} when running command for file: {path_to_format}\ncmd: {cmd}')
            sys.stdout.buffer.write(b'stderr: ' + result.stderr)
            prints()
capink is offline   Reply With Quote