Skip to content

Commit

Permalink
Support launching of console windows
Browse files Browse the repository at this point in the history
Setting CREATE_NEW_CONSOLE causes a new, unmonitored terminal window to appear
  • Loading branch information
mottosso committed Jul 20, 2017
1 parent 807a307 commit a3d89af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
27 changes: 17 additions & 10 deletions launcher/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, root, parent=None):
# The current frame is visualised by the Terminal in the GUI.
self._frames = list()

@Property(str)
@Property(str, constant=True)
def title(self):
return (api.Session["AVALON_LABEL"] or "Avalon") + " Launcher"

Expand Down Expand Up @@ -257,6 +257,7 @@ def launch(self, name):
executable=executable,
args=args,
environment=environment,
cwd=workdir
)
except ValueError:
return terminal.log(traceback.format_exc())
Expand Down Expand Up @@ -287,18 +288,24 @@ def run(self):
self.messaged.emit(line.rstrip())
self.messaged.emit("%s killed." % process["app"]["executable"])

thread = Thread()
thread.messaged.connect(lambda line: terminal.log(line, terminal.INFO))
# lib.launch might not pipe stdout,
# in which case we can't listen for it.
if popen.stdout is not None:
thread = Thread()
thread.messaged.connect(
lambda line: terminal.log(line, terminal.INFO)
)

process.update({
"app": app,
"thread": thread,
"popen": popen
})
process.update({
"app": app,
"thread": thread,
"popen": popen
})

self._processes.append(process)

self._processes.append(process)
thread.start()

thread.start()
return process

def current_frame(self):
Expand Down
16 changes: 11 additions & 5 deletions launcher/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def schedule(task, delay=10):
self._current_task = timer


def launch(executable, args=None, environment=None):
def launch(executable, args=None, environment=None, cwd=None):
"""Launch a new subprocess of `args`
Arguments:
Expand All @@ -140,6 +140,7 @@ def launch(executable, args=None, environment=None):
"""

CREATE_NO_WINDOW = 0x08000000
CREATE_NEW_CONSOLE = 0x00000010
IS_WIN32 = sys.platform == "win32"
PY2 = sys.version_info[0] == 2

Expand All @@ -159,18 +160,23 @@ def launch(executable, args=None, environment=None):
kwargs = dict(
args=[abspath] + args or list(),
env=env,
cwd=cwd,

stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,

# Output `str` through stdout on Python 2 and 3
universal_newlines=True,

shell=True
)

if IS_WIN32:
kwargs["creationflags"] = CREATE_NO_WINDOW
if environment.get("CREATE_NEW_CONSOLE"):
kwargs["creationflags"] = CREATE_NEW_CONSOLE
kwargs.pop("stdout")
kwargs.pop("stderr")
else:

if IS_WIN32:
kwargs["creationflags"] = CREATE_NO_WINDOW

popen = subprocess.Popen(**kwargs)

Expand Down

0 comments on commit a3d89af

Please sign in to comment.