Executes a Python file. The interpreter to use is chosen based on this priority order: 1. interpreter_command paramter 2. global setting "-python command-" 3. the interpreter running running PySimpleGUI :param pyfile: the file to run :type p
(pyfile, parms=None, cwd=None, interpreter_command=None, wait=False, pipe_output=False, merge_stderr_with_stdout=True)
| 23192 | |
| 23193 | |
| 23194 | def execute_py_file(pyfile, parms=None, cwd=None, interpreter_command=None, wait=False, pipe_output=False, merge_stderr_with_stdout=True): |
| 23195 | """ |
| 23196 | Executes a Python file. |
| 23197 | The interpreter to use is chosen based on this priority order: |
| 23198 | 1. interpreter_command paramter |
| 23199 | 2. global setting "-python command-" |
| 23200 | 3. the interpreter running running PySimpleGUI |
| 23201 | :param pyfile: the file to run |
| 23202 | :type pyfile: (str) |
| 23203 | :param parms: parameters to pass on the command line |
| 23204 | :type parms: (str) |
| 23205 | :param cwd: the working directory to use |
| 23206 | :type cwd: (str) |
| 23207 | :param interpreter_command: the command used to invoke the Python interpreter |
| 23208 | :type interpreter_command: (str) |
| 23209 | :param wait: the working directory to use |
| 23210 | :type wait: (bool) |
| 23211 | :param pipe_output: If True then output from the subprocess will be piped. You MUST empty the pipe by calling execute_get_results or your subprocess will block until no longer full |
| 23212 | :type pipe_output: (bool) |
| 23213 | :param merge_stderr_with_stdout: If True then output from the subprocess stderr will be merged with stdout. The result is ALL output will be on stdout. |
| 23214 | :type merge_stderr_with_stdout: (bool) |
| 23215 | :return: Popen object |
| 23216 | :rtype: (subprocess.Popen) | None |
| 23217 | """ |
| 23218 | |
| 23219 | if cwd is None: |
| 23220 | # if the specific file is not found (not an absolute path) then assume it's relative to '.' |
| 23221 | if not os.path.exists(pyfile): |
| 23222 | cwd = '.' |
| 23223 | |
| 23224 | if pyfile[0] != '"' and ' ' in pyfile: |
| 23225 | pyfile = '"' + pyfile + '"' |
| 23226 | if interpreter_command is not None: |
| 23227 | python_program = interpreter_command |
| 23228 | else: |
| 23229 | # use the version CURRENTLY RUNNING if nothing is specified. Previously used the one from the settings file |
| 23230 | # ^ hmmm... that's not the code is doing now... it's getting the one from the settings file first |
| 23231 | pysimplegui_user_settings.load() # Refresh the settings just in case they've changed via another program |
| 23232 | python_program = pysimplegui_user_settings.get('-python command-', '') |
| 23233 | if python_program == '': # if no interpreter set in the settings, then use the current one |
| 23234 | python_program = sys.executable |
| 23235 | # python_program = 'python' if running_windows() else 'python3' |
| 23236 | if parms is not None and python_program: |
| 23237 | sp = execute_command_subprocess(python_program, pyfile, parms, wait=wait, cwd=cwd, pipe_output=pipe_output, merge_stderr_with_stdout=merge_stderr_with_stdout) |
| 23238 | elif python_program: |
| 23239 | sp = execute_command_subprocess(python_program, pyfile, wait=wait, cwd=cwd, pipe_output=pipe_output, merge_stderr_with_stdout=merge_stderr_with_stdout) |
| 23240 | else: |
| 23241 | print('execute_py_file - No interpreter has been configured') |
| 23242 | sp = None |
| 23243 | return sp |
| 23244 | |
| 23245 | |
| 23246 | def execute_py_get_interpreter(): |
no test coverage detected