0

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.

2
  • There is no os.pause. Did you mean os.system("pause")? Commented Sep 6, 2013 at 16:30
  • Yes, that's what I meant, I was just too tired to look up the code. My bad. Commented Sep 6, 2013 at 23:54

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Glad you caught the fact I failed to mention python.exe instead of pythonw.exe +1
Thank you. When I used python.exe instead of pythonw.exe, I got an error the first time (saying that a .dll file was missing) but I just tried it and now it worked. Odd. Thanks for the tip.
1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.