开发者

passing variable to a batch file when called using "call" function

i want to call a batch file from another batch file and also want to pass a variable to it. lets say i want to call b.bat from a.bat. my b.bat copies files. so while calling it from a.bat , i want to pass the path of the destination folder to b.bat.

well to b 开发者_C百科more clear, the destination path will b entered by user, so it will b stored in a variable say 'x'. how do i pass the path now?


rem --- a.bat ---
set /p TargetPath=Please enter destination path: 
call b.bat "%TargetPath%"

rem --- b.bat ---
echo Copying to: %~1

As an alternative, you can simply use %TargetPath% in b.bat: environment variables are inherited by subprocesses. But passing a parameter explicitly is probably better from the flexibility and supportability point of view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜