Skip to content

Instantly share code, notes, and snippets.

@zed
Last active March 30, 2023 18:34
Show Gist options
  • Select an option

  • Save zed/7389278 to your computer and use it in GitHub Desktop.

Select an option

Save zed/7389278 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Show messages in two new console windows simultaneously.
See http://stackoverflow.com/q/19479504
"""
import sys
import platform
from subprocess import Popen
messages = 'This is Console1', 'This is Console2'
# define a command that starts new terminal
if platform.system() == "Windows":
new_window_command = "cmd.exe /c start cmd.exe /c".split()
else: #XXX this can be made more portable
new_window_command = "x-terminal-emulator -e".split()
# open new consoles, display messages
echo = [sys.executable, "-c",
"import sys; print(sys.argv[1]); input('Press Enter..')"]
processes = [Popen(new_window_command + echo + [msg]) for msg in messages]
# wait for the windows to be closed
for proc in processes:
proc.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment