windows - Why does console output keep self-referencing batch script from exiting cleanly? -


i writing self-referencing windows 10 (home ed.) batch script locate string in large number of log files, create results file and, when finished, open log file in notepad++. process takes few minutes hence self-referencing part allows me return control original command window until log file opened (and takes focus).

however, when second command window, started "start" command , "/b" switch, includes @ least 1 "echo" command won't exit cleanly , requires me press enter key exit "nested" command window.

i've distilled code down 9 lines can see mean. see in action, save following "test.bat" , run command prompt:

@echo off if "%1" equ "" call :noargs & goto :done echo there @ least 1 argument. :done exit /b :noargs echo there no arguments. start "" /b cmd /c test.bat arg1 goto :eof 

it print "there no arguments." below prompt followed "there @ least 1 argument." @ prompt , hang, waiting enter key before returning control prompt.

if remove line:

echo there @ least 1 argument. 

the enter key no longer needed second command shell exit. similarly, if output echo command redirected file issue goes away. problem occurs without echo commands if output generated eg type command seems due there being form of console output. can demonstrated commenting out both "echo" line first line "@echo off" - commands being echoed console again hangs before exiting.

i around issue changing "start" call this:

start "" /min cmd /c test.bat arg1 

however output no longer visible in minimized window it's poor solution.

i'd love know why code posted behaves way does, why won't exit cleanly without requiring enter key pressed. clue have "remarks" column in matrix on page close , exit batch files states, "make sure no text displayed in console window make close automatically @ end of batch file". seems refer windows 9.x versions of command.com - not eg windows 10 nor cmd.exe.

thanks input/thoughts.

-s1m0n-

you're misinterpreting output. if i've understood rightly, looks this:

c:\working\test>test there no arguments.  c:\working\test>there @ least 1 argument. 

that happened this:

c:\working\test>                                    <---- output first shell                 test                                <---- input there no arguments.                            <---- output first shell                                                     <---- output first shell c:\working\test>                                    <---- output first shell                 there @ least 1 argument.    <---- output second shell                                                     <---- cursor here 

the second shell running asynchronously - that's start - first shell has finished batch job , printed next prompt time second shell gets around printing output.

at point, second shell has exited, , first shell waiting enter command. doesn't know second shell has printed anything, has no reason think needs reprint prompt. if enter command, work.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)