0

I am trying to close the db2cmd after executing a command. Goal is to get this file perfect before I schedule it with a task scheduler to run everyday at 2100 hours. The batch file starts execution of the command, the command gets executed but the prompt doesn't close.

I have been through the below links but no combination is working.
How to close the command line window after running a batch file?
How to automatically close cmd window after batch file execution?

Here is my short script
start C:\"Program Files"\IBM\SQLLIB\BIN\db2cmdadmin.exe "db2 -tvf D:\stats.sql > D:\stats.output"

The command works but the prompt remains open after completion. I have tried doing -
"&& exit 0",
"exit 0" in the next line,
"exit" in the next line,
"start db2cmdadmin "db2 -tvf D:\stats.sql > D:\stats.output""

But nothing closes the prompt. How can I correct this?

Community
  • 1
  • 1
user2683109
  • 3
  • 1
  • 5
  • Why do you not put quotes around the _whole_ path? the syntax you are using (quotes _within_ the path) looks weird to me, I am even surprised that it works... you should use: `start "" "C:\Program Files\IBM\SQLLIB\BIN\db2cmdadmin.exe" ...` (so the entire path is quoted; the empty quoted string `""` is the window title; if omitted, `start` might get confused) – aschipfl Nov 08 '15 at 19:41

2 Answers2

0

I haven't tried this, but it usually works for me. On at the end of `

start `C:\"Program Files"\IBM\SQLLIB\BIN\db2cmdadmin.exe "db2 -tvf D:\stats.sql > D:\stats.output"

Put

goto eof

Then put a loop

:eof 

and exit So in total the code would be

@echo off
   start `C:\"Program Files"\IBM\SQLLIB\BIN\db2cmdadmin.exe "db2 -tvf D:\stats.sql > D:\stats.output"
goto eof

:eof
exit
  • Thanks for your answer. Even though I did not try this method, addition of /c did the trick and is much simpler than running a loop. – user2683109 Nov 07 '15 at 08:07
0

You probably want to add the command line switch /c to your command

start C:\"Program Files"\IBM\SQLLIB\BIN\db2cmdadmin.exe /c "db2 -tvf D:\stats.sql > D:\stats.output"

as explained in the manual.

mustaccio
  • 18,234
  • 16
  • 48
  • 57