Closing another cmd.exe window from batch script? Opposite of START cmd.exe /k "...." ?

C

Cindy Parker

From a DOS batch script under WinXP I launched another CommandPrompt and start a program "myserver" in
this new window with a command like:

START cmd.exe /k "myserver parm1 parm2"

The original initiating batch script ends.

Then - after a while - I start another DOS batch script and
want to close this previously created other cmd.exe window.

How can I do this?

I don't want to touch the program "myserver".
All necessary stuff should be done in the closing batch script.
And of cause I don't want to manually enter "exit" in the CommandPrompt to be closed.
All should be done automatically in/from a closing supervisor batch script.

In other words: I need the opposite of the START command.
Unfortunately there is no command like:

CLOSE "cmd.exe -title=myserver"

Is there a work around for that?

Cindy
 
F

foxidrive

From a DOS batch script under WinXP I launched another CommandPrompt and start a program "myserver" in
this new window with a command like:

START cmd.exe /k "myserver parm1 parm2"

The original initiating batch script ends.

Then - after a while - I start another DOS batch script and
want to close this previously created other cmd.exe window.

How can I do this?


What is myserver? A 32 bit Windows GUI or console command?

Have you tried this?


START "" "myserver" parm1 parm2
 
T

Tom Lavedas

From a DOS batch script under WinXP I launched another CommandPrompt and start a program "myserver" in
this new window with a command like:

START cmd.exe /k "myserver parm1 parm2"

The original initiating batch script ends.

Then - after a while - I start another DOS batch script and
want to close this previously created other cmd.exe window.

How can I do this?

I don't want to touch the program "myserver".
All necessary stuff should be done in the closing batch script.
And of cause I don't want to manually enter "exit" in the CommandPrompt to be closed.
All should be done automatically in/from a closing supervisor batch script.

In other words: I need the opposite of the START command.
Unfortunately there is no command like:

CLOSE "cmd.exe -title=myserver"

Is there a work around for that?

Cindy

Try something like this ...

taskkill /f /fi "WINDOWTITLE eq myserver"

I believe the filter name part (WINDOWTITLE) is case sensitive. I
don't think any of the rest of it is, but you can test that part.

BTW, this does not cause an orderly shutdown of the application. It
just does what the name implies - it kills it. You might also want to
look at the TaskList utility to build a confirmation test to prove
that the desired process is in fact a cmd.exe window. If there are
only two command console applications running, it will be the second
one. You could then select the PID from the second item in the
listing and use that to kill the process. (Left to the studant ;-)
_____________________
Tom Lavedas
 
T

Todd Vargo

Cindy said:
From a DOS batch script under WinXP I launched another CommandPrompt and
start a program "myserver" in
this new window with a command like:

START cmd.exe /k "myserver parm1 parm2"

The original initiating batch script ends.

Then - after a while - I start another DOS batch script and
want to close this previously created other cmd.exe window.

How can I do this?

I don't want to touch the program "myserver".
All necessary stuff should be done in the closing batch script.
And of cause I don't want to manually enter "exit" in the CommandPrompt to
be closed.
All should be done automatically in/from a closing supervisor batch
script.

In other words: I need the opposite of the START command.
Unfortunately there is no command like:

CLOSE "cmd.exe -title=myserver"

Is there a work around for that?

ISTM, you left out an important piece of information or typed the command
above incorrectly. ten.nigriv provides a good work around, but, why leave
the second CMD window open in the first place? The simple solution would be
to use /c switch instead of /k switch. You could include a /wait after
START, but you did not mention the reason for opening myserver in a separate
window. I'm surprised the START command works at all with the "myserver
parm1 parm2" in quotes. First because the START command requires a window
title parameter whenever quotes are used. Second, because myserver and the
parameters are enclosed in the same pair of quotes.
 
B

Batchman

Hi Cindy,

[SNIP]
Then - after a while - I start another DOS batch script and
want to close this previously created other cmd.exe window.

How can I do this?

Have you considered using the dos CALL command to execute all but the
first batch? CALL causes another command shell to be created and a command
(batch file perhaps) to be executed, and at the end of the CALLed item the
secondary shell is automatically closed.

Batchman - I BATCH, therefore I am!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top