简体   繁体   中英

Passing parameters to a batch file that end in a numeral

I have the requirement to pass an arguments string from one batch file to another for execution at the command line. Say we have a batch file which takes its arguments (ie the command "tail") and creates another batch file that executes those arguments. Consider file Batch1.bat:

echo %*>Batch2.bat
call Batch2.bat

If we run this with

Batch1.bat echo a b c

we get

a b c

which is fine. But if we run it with

Batch1.bat echo 1 2 3 

we get

1 2

I guess because the last argument 3 gets interpreted by batch as an operator for the following > redirection character. I know a simple fix would be to add a space, as in

echo %* >Batch2.bat

but there are occasions when the command line cannot have a trailing space, like:

Batch1 set NoEnv=

will give you an environment variable with a value of one space character, instead of deleting the environment variable.

So how do I do this? - the requirement is to have a batch file which faithfully executes its command tail (which might include items in quotes, as well as numerals)

将重定向移动到语句的前面。

>batch2.bat echo %*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM