Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOW to EXIT using "start" in batch files of MSDOS

I want to copy some files into diffent USB disks, and want to use START to open several consoles as follows:

start copy a.txt h:
start copy a.txt i:
start copy a.txt j:

But everytime I run the batch file, there are 3 consoles without exiting. How can I realize this EXIT function WITHOUT using 3 batch files and "call" commands as:

copy.bat:

call a.bat
call b.bat
call c.bat
exit

and three called batch files as:

a.bat:

start copy a.txt h:
exit

b.bat:

start copy a.txt i:
exit

c.bat:

start copy a.txt j:
exit

I already tried this, but it DOES NOT work:

start copy a.txt h: && exit
start copy a.txt i: && exit
start copy a.txt j: && exit
like image 756
little白 Avatar asked Jan 31 '12 10:01

little白


People also ask

How do I exit a batch file in DOS?

EXIT /B at the end of the batch file will stop execution of a batch file. use EXIT /B < exitcodes > at the end of the batch file to return custom return codes.

How do I exit batch mode?

Using EXIT /B will stop execution of a batch file or subroutine and return control to the command processor or to the calling batch file or code immediately. EXIT /B is available in Windows 2000 and later versions' CMD.

How do you exit a file in cmd?

To close or exit the Windows command line window, also referred to as command or cmd mode or DOS mode, type exit and press Enter . The exit command can also be placed in a batch file. Alternatively, if the window is not fullscreen, you can click the X close button in the top-right corner of the window.

How do I stop a batch script?

Ctrl+C. One of the most universal methods of aborting a batch file, command, or another program while it's running is to press and hold Ctrl + C . This keyboard shortcut sends a SIGINT signal, which cancels or terminates the currently-running program and returns you to the command line.


1 Answers

You need to escape && so it becomes part of the command executed by start and not the parent batch file.

start copy a.txt h: ^&^& exit

To close the new console even if there are errors you can do:

start "" "%comspec%" /c copy a.txt h:
like image 87
Anders Avatar answered Nov 15 '22 09:11

Anders