From b0e7526a0d4ec0ebc12eeca83bb78ef53a136199 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 31 Jan 2019 13:56:03 +0530 Subject: [PATCH] Open With: Fix using .bat files as the program not working. Fixes #1811045 [Open With won't run BAT files](https://bugs.launchpad.net/calibre/+bug/1811045) --- src/calibre/gui2/open_with.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/open_with.py b/src/calibre/gui2/open_with.py index 31ba41968d..565dcfdc50 100644 --- a/src/calibre/gui2/open_with.py +++ b/src/calibre/gui2/open_with.py @@ -123,12 +123,20 @@ if iswindows: del run_program def run_program(entry, path, parent): # noqa + import re cmdline = entry_to_cmdline(entry, path) - print('Running Open With commandline:', repr(entry['cmdline']), ' |==> ', repr(cmdline)) + flags = win32con.CREATE_DEFAULT_ERROR_MODE | win32con.CREATE_NEW_PROCESS_GROUP + if re.match(r'"[^"]+?(.bat|.cmd|.com)"', cmdline, flags=re.I): + flags |= win32con.CREATE_NO_WINDOW + console = ' (console)' + else: + flags |= win32con.DETACHED_PROCESS + console = '' + print('Running Open With commandline%s:' % console, repr(entry['cmdline']), ' |==> ', repr(cmdline)) try: with sanitize_env_vars(): process_handle, thread_handle, process_id, thread_id = CreateProcess( - None, cmdline, None, None, False, win32con.CREATE_DEFAULT_ERROR_MODE | win32con.CREATE_NEW_PROCESS_GROUP | win32con.DETACHED_PROCESS, + None, cmdline, None, None, False, flags, None, None, STARTUPINFO()) WaitForInputIdle(process_handle, 2000) except Exception as err: