2

How to automatically close command prompt window after batch file execution.

I tried command Start "" & Exit 0 but it's not working.

Start ""
@ECHO OFF
C:
cd c:\wamp\www\phpfile
php genCSV.php
"c:\program files\coreftp\coreftp.exe" -s-O -site UPLH -u D:\Files\out\*.*   -p /Import/
del /Q c:\wamp\www\txt\*.*

Solution

I used "exit /B" at the of script as per Joey's below answer.

kreya
  • 1,091
  • 5
  • 24
  • 52
  • What do you need the `start ""` for? – aschipfl Dec 12 '15 at 07:57
  • 2
    Take a look on answer on [In a Windows batch file, can you chain-execute something that is *not* another batch file?](http://stackoverflow.com/a/34231635/3074564) It explains in detail how batch file processing can be exited with or without exiting also command processing, i.e. closing console window. – Mofi Dec 12 '15 at 10:36

2 Answers2

1

If you really want to close even an interactive session, then just use exit. Generally though, e.g. from Explorer, batch files are started with cmd /c which will close the console after the batch file completes.

Joey
  • 344,408
  • 85
  • 689
  • 683
0

Make sure no text is displayed in the console window to make it close automatically at the end of the batch file. Use the EXIT command with the /B which ends the batch file right then the exit returns to the command window. The clear console will close on certain systems. See http://www.robvanderwoude.com/exit.php

You could place this in your Batch file (notice the squiggly after the t in Exit - you most likely will need to use that - but you can try with out it.

Set WshShell = CreateObject("WScript.Shell") 
WshShell.SendKeys "Exit~"
WshShell.SendKeys "{ENTER}"
Ken
  • 2,518
  • 2
  • 27
  • 35