Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am launching 4 executables from a batch script:

@echo off
start ../../../../LD_Server.exe 12321 23432 11221 3
start LD_Client.exe 12321 pero
start LD_Client.exe 23432 tina
start LD_Client.exe 11221 sanja

This opens 4 cmd windows but after they do their work they all close. I want them to stay opened so I can read the output. How?

share|improve this question
    
mine stay open though i don't have that or an exe to try on at the moment, I just tried start dir, start cmd /k dir. but try start cmd /k ld_client.exe <-- do they stay open then. contrast with cmd /c where they'd close. maybe yours close even with a /k. i think and thought /k was default. – barlop Apr 24 '13 at 8:05
    
by the way, you can do start LD_Client.exe 12321 pero >c:\a.a to redirect to a file then the next one use >> to append i.e. start LD_Client.exe 23432 tina >>c:\a.a But that doesn't directly answer your q. Try the cmd /k I mention see if that helps – barlop Apr 24 '13 at 8:08
    
Hm, weird. Maybe it really works differently with .exe's. Anyhow, it's resolved now, see the answer below. Also thanks for suggestions! – Primož Kralj Apr 24 '13 at 12:20
    
You clearly didn't try my suggestion of cmd /k ld_client. It may have worked. But even though it's fine for you now. For the sake of knowing what's going on, can you try start cmd LD_Client.EXE and see if that closes immediately? Then try start cmd /k LD_Client.EXE. And report back. – barlop Apr 24 '13 at 12:44
    
Se comment on your question. – Primož Kralj Apr 24 '13 at 13:01
up vote 2 down vote accepted
@echo off
start %COMSPEC% /k ../../../../LD_Server.exe 12321 23432 11221 3
start %COMSPEC% /k LD_Client.exe 12321 pero
start %COMSPEC% /k LD_Client.exe 23432 tina
start %COMSPEC% /k LD_Client.exe 11221 sanja

%COMSPEC% is an environment variable that points to your system's command interpreter (on Windows NT, C:\Windows\System32\cmd.exe), and the /k switch prevents the specified command's window from closing after execution.

share|improve this answer
    
Can you explain what these commands do and why they work? – Marcks Thomas Apr 24 '13 at 9:37
    
though worth noting that if you open a cmd prompt and do start dir, it opens a new cmd prompt runs dir -and does not close that new cmd prompt- so it looks like /k is the default. And it looks like %COMSPEC% might also be default considering that start dir works. Maybe it works differently with EXEs? – barlop Apr 24 '13 at 11:45
    
Works great, I just needed to copy the `LD_Server to the same directory where the batch script resides, otherwise I got ".." unrecognised program. – Primož Kralj Apr 24 '13 at 12:19

from a cmd window.

start dir <-- opens new cmd window and keeps it open. so it by default does start cmd /k dir.

start cmd wget (equivalent to your exe) closes it, so seems to do start cmd /c wget.

start cmd /k wget (as in my suggestion four hours ago that you perhaps couldn't read or understand or bother trying) keeps it open. Similarly with your exe.

furthermore it's a pretty lame question 'cos if you just googled how to stop cmd window from closing, you'd see stranght away about cmd /k and cmd /c, And if you did cmd /? you'd see them. It's not like with linux where you have tons of switches and you have to read pages and pages to find what you want.

share|improve this answer
    
I tried with start cmd LD_Client.exe 12321 pero in batch script and that resulted in creating more and more cmd windows until my computer crashed. Have no intentions to experiment anymore ;) – Primož Kralj Apr 24 '13 at 13:01
    
@PrimožKralj I never said to try that. I said "try start cmd /k ld_client.exe " – barlop Apr 24 '13 at 13:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .