0

From this question, I solved that problem but now another problem is occured.Now my first .exe file is opening by these codes in Pygame;

process = subprocess.Popen(["wtf.exe"])
output, errors = process.communicate()

This file (wtf.exe) asking information to user before opening the Pygame and putting that information in to the Pygame;

enter image description here

When I confirm these informations, it's opening the Pygame screen with information I gave in first program and closing the first program;

enter image description here

So far everything is fine, when I click to the 'play' , it's opening another file in terminal; but last file's datas still there.

enter image description here

You see, first picture's datas here, it should be without these datas. Why terminal is didn't clean itself? It's another .exe file running in terminal, a new file on a 'new' terminal, but it looks it's not new. How do I clean the terminal after first file processed? As you know these are .exe files working on terminal, and I can't clear the terminal manually, I have to write some codes into that files, but I have no idea what to do.

Edit: I gave some unacceptable informations on purpose and check this picture please:

enter image description here

Edit2: Here is the video of my problem.

Community
  • 1
  • 1
  • Do you want it to start at the top or can your prompt be at the bottom? – Marcello B. Jan 03 '15 at 21:51
  • I want to start it at the top of course, and this problem is really weird. It should be another terminal, because I opening a different .exe file, but as you see first datas still there. The data that I taking from user must NOT be in terminal if second program is running. –  Jan 03 '15 at 21:53
  • Oh I understand why don't you just use one terminal window and clear it out after the information has been entered just by doing a for loop with empty print statements 2000 will usually clear terminal windows – Marcello B. Jan 03 '15 at 21:55
  • @Ondeckshooting Well it's not a solution actually, it's like hiding the first data :-) but I want to clear it, it's more "programmer" also this problem shouldn't be occured, as I said second program is another .exe file.. –  Jan 03 '15 at 21:57
  • I've used this before Its been a long time since I have used this but I think this question is similar to what you are asking and should help you out. I know there's a module that can do all sorts of things with command prompt on windows but nothing on anything Unix: http://stackoverflow.com/questions/12586601/remove-last-stdout-line-in-python – Marcello B. Jan 03 '15 at 22:04
  • 1
    Your script runs via the console program py.exe, which starts python.exe. When you run `subprocess.Popen('wtf.exe')`, the child process inherits the current console. You could first run `subprocess.Popen('cls', shell=True)` to have the shell clear the screen. Or you could instruct Windows to create a new console: `subprocess.Popen('wtf.exe', creationflags=subprocess.CREATE_NEW_CONSOLE)`. – Eryk Sun Jan 03 '15 at 23:06

2 Answers2

1

cls internal command (Windows) / clear command on *nix clear the terminal screen and its scrollback buffer if possible:

import os

os.system('cls')

Try it before making a comment.

As an alternative, you could start a new console window (creationflags=CREATE_NEW_CONSOLE on Windows) for each command or just the last command instead i.e., when a command ends its window is closed and therefore there is nothing to clean.

You could also run your parent script as a GUI program (use .pyw file extension) without the console i.e., if a child process needs the console; it has to allocate its own.

Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670
1

@J.F. Sebastian gave you one approach, which is to clear the screen from within your code.

However, as you are already using pygame, you can use the inputbox module to prompt the user for their input.

This way, you eliminate the problem completely.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284