How to close command window?

  • Thread starter Thread starter Peter Jensen
  • Start date Start date
P

Peter Jensen

X-No-Archive: Yes


I've tried various combinations with start, cmd and command, but no
luck. Exit does nothing. How can I get the command window to close
automatically after starting a Windows app with a batch file?


@echo off
echo. test> c:\test1.tmp
copy /y c:\test1.tmp c:\test2.tmp
type c:\test2.tmp
del c:\test?.tmp
"C:\Programs\Windows NT\Accessories\wordpad.exe"
exit
 
Peter said:
I've tried various combinations with start, cmd and command, but no
luck. Exit does nothing. How can I get the command window to close
automatically after starting a Windows app with a batch file?
@echo off
echo. test> c:\test1.tmp
copy /y c:\test1.tmp c:\test2.tmp
type c:\test2.tmp
del c:\test?.tmp
"C:\Programs\Windows NT\Accessories\wordpad.exe"
exit

Try use "cls" instead of "exit" at the end of this file.
 
Sun, 02 Mar 2008 13:05:12 +0100 from Arkadiusz 'Black Fox' Artyszuk
Try use "cls" instead of "exit" at the end of this file.

Why do you make that suggestion? Have you tried it yourself? I think
if you do, you'll find it doesn't do what the OP wants.

To the OP,

Your problem is the way you're invoking Wordpad. A batch file is
sequential, so the EXIT command doesn't get executed until you've
closed Wordpad. Try it and you'll see.

The cure is to use the START command:
START "Wordpad" "C:\Programs\Windows NT\Accessories\wordpad.exe"
The START command starts a program as a detached process and
immediately returns control to the command window, which in this case
means to the batch file.

Ordinarily the window title (first argument) is optional, but in this
case it seems the command prompt gets confused by the quotes around
the program path unless the title is supplied.
 
Back
Top