mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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)
This commit is contained in:
parent
6dba8ca536
commit
b0e7526a0d
@ -123,12 +123,20 @@ if iswindows:
|
|||||||
del run_program
|
del run_program
|
||||||
|
|
||||||
def run_program(entry, path, parent): # noqa
|
def run_program(entry, path, parent): # noqa
|
||||||
|
import re
|
||||||
cmdline = entry_to_cmdline(entry, path)
|
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:
|
try:
|
||||||
with sanitize_env_vars():
|
with sanitize_env_vars():
|
||||||
process_handle, thread_handle, process_id, thread_id = CreateProcess(
|
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())
|
None, None, STARTUPINFO())
|
||||||
WaitForInputIdle(process_handle, 2000)
|
WaitForInputIdle(process_handle, 2000)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user