MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / execute_command_blocking

Function execute_command_blocking

DemoPrograms/Demo_PyCharm_Launcher.py:68–90  ·  view source on GitHub ↗

Creates a subprocess using supplied command and arguments. Will not return until the process completes running :param command: The command (full path) to execute :param args: a tuple of arguments :return: string with the output from the command

(command, *args)

Source from the content-addressed store, hash-verified

66
67
68def execute_command_blocking(command, *args):
69 """
70 Creates a subprocess using supplied command and arguments.
71 Will not return until the process completes running
72 :param command: The command (full path) to execute
73 :param args: a tuple of arguments
74 :return: string with the output from the command
75
76 """
77 print(f'Executing {command} with {args}')
78 expanded_args = [a for a in args]
79 try:
80 sp = subprocess.Popen([command, expanded_args], shell=True,
81 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
82 out, err = sp.communicate()
83 if out:
84 print(out.decode("utf-8"))
85 if err:
86 print(err.decode("utf-8"))
87 except Exception as e:
88 sg.Print(f'execute got exception {e}')
89 out = ''
90 return out
91
92
93# ----------------------------- When program is first started -----------------------------

Callers 1

mini_launcherFunction · 0.70

Calls 1

PrintMethod · 0.80

Tested by

no test coverage detected