I use Dev-Pascal on Windows 8.
When I run the program, cmd.exe opens and runs the program and closes automatically.
How can I prevent this?
Try to add readln; before end.
This will make your program to pause till you hit enter.
Related
when I open the command prompt to work on it, it's close after few seconds Immediately without close it or make anything exit..
I search about solution It didn't work, any solution ?
i'm using windows 10 and trying to start an exe in diffrent folders sequentially. The idea is to use popen from subprocess and wait for the process to finish. The problem is, that the window does only close if I click on it or hit a key. On a windows 7 machine however the window is closing and subprocess.wait() finishes.
import os
import subprocess
for path in ["C:\tmp\", "C:\tmp2\"]:
os.chdir(path)
mywindow = subprocess.Popen(["my.exe",
#stdin=subprocess.PIPE,
#stdout=subprocess.PIPE,
#stderr=subprocess.PIPE,
#shell=True,
creationflags=subprocess.CREATE_NEW_CONSOLE,
env=dict(os.environ, **{"test":"AUTO"}))
mywindow.wait()
I used creationflags=subprocess.CREATE_NEW_CONSOLE, because I need to be able to start my.exe multiple times and be able to read the output on another console. But in some cases I want to wait for my process to end.
Update:
After eryksuns comment I'm pretty sure that this more of a windows problem than a python one.
On Windows 7 "my.exe" exits and wait() returns afterwards. On windows 10 however, I have to click somewhere on the screen or press any key, in order to close the console window "my.exe" opens. Afterwards the wait()returns. Disabeling the cmd quick edit mode had no effect.
I have a program the opens a window, reads a config file, then closes the window a fraction of a second later, then continues running in background. I want to be able to start this program one way or another without the window appearing in the first place.
Is there a way for me to launch the program (preferably on PC startup) but suppress any windows it creates?
I do not have the source code for the program in question. In that regard I am an end-user.
use a vbs script to open it:
set obj = createobject("wscript.shell")
obj.run "prog.exe",0,false
call that prog.vbs or whatever, and put it in:
"%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup"
There is a VB6 application. It can be run with command line parameters to create some report in a text file.
The problem is that when started from a batch file, application returns control immediately, so the following commands start executing. I need these following commands to wait until the VB6 app finishes its work.
How to achieve that?
The Start command has a wait switch which does exactly what you want.
c:\start /w notepad
You could rewrite the VB6 program as a console application.
I am coming from XCode and this is probably a stupid question, but after I build my program successfully, I try to click on the Application in the debug folder and the window just closes. How do I run my application that I create?
The above answers are correct, but if your question is simply why your command prompt closes immediately upon your program's termination, you have two options:
Put a breakpoint on your main()'s } before you run.
Use Ctrl+F5, which will add a "Press any key to continue" at the end so you can see all of your program's output, but it will launch the application without attaching the debugger.
You can compile and run the program by pressing F5.
However, if you're talking about non-gui console application which just prints something and exists,
the output window will close right away. If this is the case, you might want to open command prompt (cmd.exe) and run it from there manually, or insert some "wait for keypress" handling, such as getchar().
Otherwise, there might be something wrong with your program :)
Debug --> Run
or
press F5