-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent creating new console on Windows #346
Conversation
Thanks! I've got a couple of concerns about doing this:
|
@takluyver No, this flags just prevents creating console window if the parent process is GUI app (has no own console handle), but the stdin/out functionality should not be affected. Just to make sure, I have created simple proof-of-concept script that shows that def test():
import subprocess
with subprocess.Popen(['cmd', '/c', 'dir'],
creationflags=0x08000000, # CREATE_NO_WINDOW
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False) as p:
out = p.stdout.read()
return out.decode('utf-8')
if __name__ == '__main__':
import ctypes
MessageBox = ctypes.windll.user32.MessageBoxW
MessageBox(None, test(), 'cmd', 0) Now when I run it via In case when the script is run via P.S. This all is caused by Windows weird separation for console vs GUI apps, that simply does not exist in UNIX world, and I wouldn't care, but I recently have to work on Windows workstation :). |
@takluyver Hello, Is there anything else I can do to get this checked in? |
Oh sorry, it had just dropped off my radar. Can you confirm that if you use this option from a process running in a console, without piping stdout/stderr, the child process can still write to the console that it's in? If this causes problems for Windows users when we release it, I might ping you to ask about it. |
Yes, the proof is my post above: #346 (comment) |
Sorry, that's not quite what I meant - I'm asking you to do it without |
@takluyver Yes I now get your point, let me rework the patch so it takes this countermeasure only for |
When running Jupyter via pythonw e.g. pythonw -m qtconsole, jupyter_client launches new kernel via python.exe which is a console application on Windows - a side-effect of that is a new empty console window created and shown as long as kernel is running. This patch adds CREATE_NO_WINDOW 0x08000000 to Windows specific creationflags. This flag is not exported by subprocess module therefore has to be provides numerically.
Thanks, that looks good to me now. :-) |
Backport PR #346 on branch 5.x
@takluyver Thanks a lot! Cheers. |
When running Jupyter via pythonw e.g. pythonw -m qtconsole, jupyter_client launches new kernel via python.exe which is a console application on Windows - a side-effect of that is a new empty console window created and shown as long as kernel is running.
This patch adds CREATE_NO_WINDOW 0x08000000 to Windows specific creationflags. This flag is not exported by subprocess module therefore has to be provides numerically.
Read more, e.g.:
https://stackoverflow.com/questions/2935704/running-shell-commands-without-a-shell-window