使用&QUOT调用时传递变量的批处理文件;调用"功能 [英] passing variable to a batch file when called using "call" function

查看:98
本文介绍了使用&QUOT调用时传递变量的批处理文件;调用"功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一个调用批处理文件的批处理文件,并希望将变量传递给它。可以说,我想从a.bat调用b.bat。我b.bat复制文件。因此,虽然从a.bat调用它,我想传递的目标文件夹b.bat的路径。结果
以及为b更加清晰,目标路径将用户B进入,所以将b存储在一个变量说'X'。我现在该如何传递路径?


解决方案

  REM --- a.bat ---
集/ p = TARGETPATH​​请输入目标路径:
叫b.bat%TARGETPATH​​%REM --- b.bat ---
回声复制到:%〜1

作为一种替代方法,你可以简单地使用%TARGETPATH​​%在b.bat:环境变量由子进程继承。但是传递一个明确的参数大概是从视图的灵活性和可支持性好点。

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 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.

这篇关于使用&QUOT调用时传递变量的批处理文件;调用"功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆