1

So, one day, I'm just sitting there making batch files and I made the following:

@echo off
cd C:\Program Files\SomeDir\
start /MAX /WAIT SomeFile.bat
pause >nul

I know there's probably a milion things I'm doing wrong there but I want to focus on the fact that, when I open that file everything is alright until I exit and switch back to the original command prompt where i get the following Terminate Batch job (Y/N). This also does not allow any further code to go ahead beacause I tried putting echoafter start.

I want to get rid of that prompt so that my code can just go ahead. I never expierienced that problem until now. If this helps, I'm on windows 7.

Please help and thanks in advance.

user9123
  • 581
  • 1
  • 10
  • 21
  • Don't use `Start` with your batch file `Call` it instead. If there's a need for the `/MAX` option, _(doubtful)_, consider using that against `Cmd.exe` instead. – Compo Sep 21 '17 at 20:13
  • Thanks for your help but I wanted to make the batch file open in another window, this is because I wanted to make a password system. I was going to put `:x` under echo and `goto x` at the bottom to make the window reopen if it is closed. This is why I used `/WAIT`. On the other window; if the password is correct, it will execute a command. So basicaly, I want to protect the window from being closed without using outside apps. – user9123 Sep 21 '17 at 20:31
  • No, you will not be compiling a batch file, you'll only be running a batch file extracted from a self extracting executable. You cannot stop users from closing a window without locking down the system such that it is effectively unusable. – Compo Sep 21 '17 at 20:58
  • This is a bug in CMD. When it waits on a program that exits with the status code `STATUS_CONTROL_C_EXIT` (0xC000013A) , it blindly assumes the program was killed with Ctrl+C or Ctrl+Break in the current console, instead of checking whether its own console control handler was called. This makes it either print "^C" in interactive mode or the terminate batch job prompt in batch mode. For example, if you have Python installed, try `start /wait python -c "raise SystemExit(0xC000013A - 2**32)"`. – Eryk Sun Sep 21 '17 at 22:22
  • When a console is closed, the programs attached to it can get a `CTRL_CLOSE_EVENT` if they've registered a console ctrl handler. They're given 5 seconds to clean up and exit with their own status code. Otherwise the session server (csrss.exe) kills them with the status code `STATUS_CONTROL_C_EXIT`. But CMD doesn't provide a way for a batch script to register a cleanup routine for a graceful exit with a different status code. – Eryk Sun Sep 21 '17 at 22:28
  • The answers to the second duplicate provide a workaround. – Harry Johnston Sep 21 '17 at 23:53
  • This works: `echo Y | start /wait cmd /c Install.bat` When the second script is finished, it echoes "Y" to the "Terminate Batch job" and closes the first script. – MokiTa May 16 '19 at 09:08

0 Answers0