Windows Start command handles EXE and BAT differently, the latter is erroneous

How can I run a batch file with arguments enclosed in double quotes using the Start command?

If you are using an EXE file, it works ( calc

- this is just an example you can test with):

start "Some Title" "calc.exe" "arg1" "arg 2" "arg  3"

      

In the same batch file calling the syntax there is no: (in the above replacement, only the extension was replaced)

start "Some Title" "calc.bat" "arg1" "arg 2" "arg  3"

      

Mistake:

'calc.bat "arg1" "arg" is not recognized as an internal or external command, runtime program, or batch file.

(The content of the file calc.bat

is irrelevant; it may even be zero length.)

How can I start a startup calc.bat

using a commandstart

(asynchronously, in a separate window) with arguments arg1

, arg 2

and arg 3

?

Of course, if you supply the arguments without quotes, it works:

start "Some Title" "calc.bat" arg1 arg2 arg3

      


EDIT:

What I really need is start_all.bat

one that launches 3 parallel processes in 3 new windows:

set user="abc"
start "Run 1" "calc.bat" "%user%" "arg 1" "arg 2" "arg 3"
start "Run 2" "calc.bat" "%user%" "arg 4" "arg 5" "arg 6"
start "Run 3" "calc.bat" "%user%" "arg 7" "arg 8" "arg 9"

      

but this only works with EXE, not BAT.

calc.bat

could be something simple like

@echo 1: `%1`
@echo 2: `%2`
@echo 3: `%3`
@pause

      

 

Additional question: what if a path with space is present?

set user="abc"
start "Run 1" "c:\batch files\calc.bat" "%user%" "arg 1" "arg 2" "arg 3"
start "Run 2" "c:\batch files\calc.bat" "%user%" "arg 4" "arg 5" "arg 6"
start "Run 3" "c:\batch files\calc.bat" "%user%" "arg 7" "arg 8" "arg 9"

      

+3


source to share


3 answers


When used start

to invoke a batch file, it actually calls cmd /K

implicitly to run the batch file:

start "Some Title" cmd /K "calc.bat" "arg1" "arg 2" "arg  3"

      

The part cmd /K

uses upper and trailing quotes, leaving an invalid command line:

calc.bat" "arg1" "arg 2" "arg  3

      

To compensate for this, provide an additional district pair of quotes; avoid them so that the arguments appear in the hosting instance cmd

.



start "Some Title" ^""calc.bat" "arg1" "arg 2" "arg  3"^"

      

However, these nested quotes are most likely confusing the command start

, so it no longer recognizes the batch file (path to) you are trying to invoke. To avoid this, you must explicitly specify the part cmd /K

:

start "Some Title" cmd /K ^""calc.bat" "arg1" "arg 2" "arg  3"^"

      

Or, using the full path to the batch file:

start "Some Title" cmd /K ^""C:\Batch Files\calc.bat" "arg1" "arg 2" "arg  3"^"

      

+3


source


you can of course call a package like this

start "Title" calc.bat "arg1" "arg 2"

      

The problem is with your party. Let's say you are using ping.exe in a package. Instead of this:

ping %1 %2 %3

      

You should:

ping %~1 %~2 %~3

      

this will catch all arguments even in quotes.

so if you do this:

start ping.bat "127.0.0.1" "-n 6" "-a"

      

it will work

CHANGE calc.bat should be:

@echo 1: %~1
@echo 2: %~2
@echo 3: %~3
@pause

      

Which in the example ping.bat

will do exactly this:



1: 127.0.0.1
2: -n 1
3: -a
Press any key to continue . . .

      

Finally, if you take what you mentioned in the comment to run the package 3 times, with different parameters for each. Then you will have content calc.bat

like this

ping %~1 %~2 %~3
ping %~4 %~5 %~6
ping %~7 %~8 %~9

      

then you call it like this.

start calc.exe "127.0.0.1% "-n 6" "-a" "192.0.1.2" "-n 2" "-a" "128.0.9.1% "-n 1" "-a"

      

LAST EDIT

If you need to call the beginning using a path, you need to call like this:

start "title" /D "c:\batch files" calc.bat "arg1" "arg2" "arg 3"

      

So, after a lot of discussion and not everyone seems to understand how the start works when the commands to other files and are persistent that / D is wrong, here is another but wrong solution.

start "Some Title" cmd /K ^""C:\Batch Files\calc.bat" "arg1" "arg 2" "arg  3"^"

      

Note. Can be used with / C as well or just cmd. K will just keep the window open.

This is more or less what the other answer says, but note that you are calling cmd / K. While this will work, it is wrong, you are calling cmd with startup, which in fact also calls cmd by default. It defeats the purpose of use anyway. If start was only used to send the header, this could have been done in the batch file already, and you could just call the package without a path.

+1


source


You can try calling the standard interpreter and escape the quotes like this:

start "Some Title" "%COMSPEC%" /c"calc.bat ^"arg1^" ^"arg 2^" ^"arg 3^""

0


source







All Articles