@@ -8226,48 +8226,66 @@ def _run_process(self, application, arguments, apppath, romext, non_blocking_fla
82268226
82278227 # Standalone launcher where application is a LNK file
82288228 if app_ext == 'lnk' or app_ext == 'LNK':
8229+ if ADDON_RUNNING_PYTHON_2:
8230+ c = 'start "AEL" /b "{}"'.format(application).encode('utf-8')
8231+ elif ADDON_RUNNING_PYTHON_3:
8232+ c = 'start "AEL" /b "{}"'.format(application)
8233+ else:
8234+ raise TypeError('Undefined Python runtime version.')
82298235 log_debug('_run_process() (Windows) Launching LNK application')
8230- retcode = subprocess.call('start "AEL" /b "{}"'.format(application).encode('utf-8') , shell = True)
8236+ retcode = subprocess.call(c , shell = True)
82318237 log_info('_run_process() (Windows) LNK app retcode = {}'.format(retcode))
82328238
82338239 # ROM launcher where ROMs are LNK files
82348240 elif romext == 'lnk' or romext == 'LNK':
8241+ if ADDON_RUNNING_PYTHON_2:
8242+ c = 'start "AEL" /b "{}"'.format(arguments).encode('utf-8')
8243+ elif ADDON_RUNNING_PYTHON_3:
8244+ c = 'start "AEL" /b "{}"'.format(arguments)
8245+ else:
8246+ raise TypeError('Undefined Python runtime version.')
82358247 log_debug('_run_process() (Windows) Launching LNK ROM')
8236- retcode = subprocess.call('start "AEL" /b "{}"'.format(arguments).encode('utf-8') , shell = True)
8248+ retcode = subprocess.call(c , shell = True)
82378249 log_info('_run_process() (Windows) LNK ROM retcode = {}'.format(retcode))
82388250
8239- # CMD/BAT files in Windows
8251+ # CMD/BAT applications in Windows.
82408252 elif app_ext == 'bat' or app_ext == 'BAT' or app_ext == 'cmd' or app_ext == 'CMD':
82418253 # Workaround to run UNC paths in Windows.
82428254 # Retroarch now support ROMs in UNC paths (Samba remotes)
82438255 new_exec_list = list(exec_list)
8244- for i, _ in enumerate( exec_list):
8245- if exec_list[i][0] == '\\':
8246- new_exec_list[i] = '\\' + exec_list[i]
8247- log_debug('_run_process() (Windows) Before arg #{} = "{}"'.format(i, exec_list[i]))
8248- log_debug('_run_process() (Windows) Now arg #{} = "{}"'.format(i, new_exec_list[i]))
8256+ for i in range(len( exec_list) ):
8257+ if exec_list[i][0] != '\\': continue
8258+ new_exec_list[i] = '\\' + exec_list[i]
8259+ log_debug('_run_process() (Windows) Before arg #{} = "{}"'.format(i, exec_list[i]))
8260+ log_debug('_run_process() (Windows) Now arg #{} = "{}"'.format(i, new_exec_list[i]))
82498261 exec_list = list(new_exec_list)
82508262 log_debug('_run_process() (Windows) exec_list = {}'.format(exec_list))
8251- log_debug('_run_process() (Windows) Launching BAT application')
8263+ log_debug('_run_process() (Windows) Launching BAT/CMD application')
82528264 log_debug('_run_process() (Windows) Ignoring setting windows_cd_apppath')
82538265 log_debug('_run_process() (Windows) Ignoring setting windows_close_fds')
82548266 log_debug('_run_process() (Windows) show_batch_window = {}'.format(self.settings['show_batch_window']))
82558267 info = subprocess.STARTUPINFO()
82568268 info.dwFlags = 1
82578269 info.wShowWindow = 5 if self.settings['show_batch_window'] else 0
8258- retcode = subprocess.call(exec_list, cwd = apppath.encode('utf-8'), close_fds = True, startupinfo = info)
8259- log_info('_run_process() (Windows) Process BAR retcode = {}'.format(retcode))
8270+ if ADDON_RUNNING_PYTHON_2:
8271+ apppath_t = apppath.encode('utf-8')
8272+ elif ADDON_RUNNING_PYTHON_3:
8273+ apppath_t = apppath
8274+ else:
8275+ raise TypeError('Undefined Python runtime version.')
8276+ retcode = subprocess.call(exec_list, cwd = apppath_t, close_fds = True, startupinfo = info)
8277+ log_info('_run_process() (Windows) Process BAT/CMD retcode = {}'.format(retcode))
82608278
82618279 # Normal Windows application.
82628280 else:
82638281 # --- Workaround to run UNC paths in Windows ---
82648282 # Retroarch now support ROMs in UNC paths (Samba remotes)
82658283 new_exec_list = list(exec_list)
8266- for i, _ in enumerate( exec_list):
8267- if exec_list[i][0] == '\\':
8268- new_exec_list[i] = '\\' + exec_list[i]
8269- log_debug('_run_process() (Windows) Before arg #{} = "{}"'.format(i, exec_list[i]))
8270- log_debug('_run_process() (Windows) Now arg #{} = "{}"'.format(i, new_exec_list[i]))
8284+ for i in range(len( exec_list) ):
8285+ if exec_list[i][0] != '\\': continue
8286+ new_exec_list[i] = '\\' + exec_list[i]
8287+ log_debug('_run_process() (Windows) Before arg #{} = "{}"'.format(i, exec_list[i]))
8288+ log_debug('_run_process() (Windows) Now arg #{} = "{}"'.format(i, new_exec_list[i]))
82718289 exec_list = list(new_exec_list)
82728290 log_debug('_run_process() (Windows) exec_list = {}'.format(exec_list))
82738291
@@ -8279,13 +8297,20 @@ def _run_process(self, application, arguments, apppath, romext, non_blocking_fla
82798297 log_debug('_run_process() (Windows) Launching regular application')
82808298 log_debug('_run_process() (Windows) windows_cd_apppath = {}'.format(windows_cd_apppath))
82818299 log_debug('_run_process() (Windows) windows_close_fds = {}'.format(windows_close_fds))
8300+ # In Python 3 use Unicode to call functions in the subprocess module.
8301+ if ADDON_RUNNING_PYTHON_2:
8302+ apppath_t = apppath.encode('utf-8')
8303+ elif ADDON_RUNNING_PYTHON_3:
8304+ apppath_t = apppath
8305+ else:
8306+ raise TypeError('Undefined Python runtime version.')
82828307 # Note that on Windows, you cannot set close_fds to true and also redirect the
82838308 # standard handles by setting stdin, stdout or stderr.
82848309 if windows_cd_apppath and windows_close_fds:
8285- retcode = subprocess.call(exec_list, cwd = apppath.encode('utf-8') , close_fds = True)
8310+ retcode = subprocess.call(exec_list, cwd = apppath_t , close_fds = True)
82868311 elif windows_cd_apppath and not windows_close_fds:
82878312 with open(g_PATHS.LAUNCH_LOG_FILE_PATH.getPath(), 'w') as f:
8288- retcode = subprocess.call(exec_list, cwd = apppath.encode('utf-8') , close_fds = False,
8313+ retcode = subprocess.call(exec_list, cwd = apppath_t , close_fds = False,
82898314 stdout = f, stderr = subprocess.STDOUT)
82908315 elif not windows_cd_apppath and windows_close_fds:
82918316 retcode = subprocess.call(exec_list, close_fds = True)
@@ -8298,20 +8323,23 @@ def _run_process(self, application, arguments, apppath, romext, non_blocking_fla
82988323 log_info('_run_process() (Windows) Process retcode = {}'.format(retcode))
82998324
83008325 elif is_android():
8301- retcode = os.system("{} {}".format(application, arguments).encode('utf-8'))
8326+ if ADDON_RUNNING_PYTHON_2:
8327+ c = '{} {}'.format(application, arguments).encode('utf-8')
8328+ elif ADDON_RUNNING_PYTHON_3:
8329+ c = '{} {}'.format(application, arguments)
8330+ else:
8331+ raise TypeError('Undefined Python runtime version.')
8332+ retcode = os.system(c)
83028333 log_info('_run_process() Process retcode = {}'.format(retcode))
83038334
83048335 # New in 0.9.7: always close all file descriptions except 0, 1 and 2 on the child
8305- # process. This is to avoid Kodi opens sockets be inherited by the child process. A
8336+ # process. This is to avoid Kodi open sockets be inherited by the child process. A
83068337 # wrapper script may terminate Kodi using JSON RPC and if file descriptors are not
8307- # closed Kodi will complain that the remote interfacte cannot be initialised. I believe
8308- # the cause is that the socket is kept open by the wrapper script.
8338+ # closed Kodi will complain that the remote interface cannot be initialised. I believe
8339+ # the cause is that the listening socket is kept open by the wrapper script.
83098340 elif is_linux():
8310- # Old way of launching child process. os.system() is deprecated and should not
8311- # be used anymore.
8312- # os.system('"{}" {}'.format(application, arguments).encode('utf-8'))
8313-
8314- # New way of launching, uses subproces module. Also, save child process stdout.
8341+ # os.system() is deprecated and should not be used anymore, use subprocess module.
8342+ # Also, save child process stdout to a file.
83158343 if non_blocking_flag:
83168344 # In a non-blocking launch stdout/stderr of child process cannot be recorded.
83178345 log_info('_run_process() (Linux) Launching non-blocking process subprocess.Popen()')
@@ -8325,10 +8353,6 @@ def _run_process(self, application, arguments, apppath, romext, non_blocking_fla
83258353 if self.settings['lirc_state']: xbmc.executebuiltin('LIRC.start')
83268354
83278355 elif is_osx():
8328- # Old way
8329- # os.system('"{}" {}'.format(application, arguments).encode('utf-8'))
8330-
8331- # New way.
83328356 with open(g_PATHS.LAUNCH_LOG_FILE_PATH.getPath(), 'w') as f:
83338357 retcode = subprocess.call(exec_list, stdout = f, stderr = subprocess.STDOUT)
83348358 log_info('_run_process() Process retcode = {}'.format(retcode))
0 commit comments