Tensigh
Tensigh

Reputation: 1050

Python script displays output in command window but nothing shows in Windows

I've written a script that works great at a command prompt, but it only displays the last line if I double click on the script.py icon on my desktop.

The function in the script runs perfectly but once it finds a match it's supposed to display the output on the screen. At the end, I have an os.pause statement and THAT displays when the script is done, but nothing else displays on the screen.

I AM executing it using pythonw.exe. What else should I check?

Thank you.

Upvotes: 0

Views: 2477

Answers (2)

tdelaney
tdelaney

Reputation: 77347

pythonw supresses the console window that is created when a python script is executed. Its intended for programs that open their own GUI. Without pythonw, a python gui app would have its regular windows plus an extra console floating around. I'm not sure what pythonw does to your stdout, but os.isatty() returns False and I assume stdout/err are just dumped into oblivion. If you run a DOS command like os.system("pause"), Windows creates a new console window for that command only. That's what you see on the screen.

If you want to see your script output, you should either run with python.exe and add an input prompt at the end of the script as suggested by @GaryWalker, or use a gui toolkit like tcl/tk, Qt or wxPython.

Upvotes: 2

Gary Walker
Gary Walker

Reputation: 9134

I've used a script like before and it seemed ok to me

print("Hello world")
input("Press return to exit")

Upvotes: 1

Related Questions