0

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?

1
  • Please edit your question to reflect the fact that you want to pass a variable from vbscript. Commented Mar 30, 2010 at 8:11

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

6 Comments

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?
i tried this with my html code: dim shell,x x="D:\d" set shell=createobject("wscript.shell") shell.run "c.bat %x%" set shell=nothing my c.bat is:xcopy %1 D:\o\ /E it doesn,t work. i am trying to pass a variable from vb to batch. can u please help me out
@sushant -- man, you need to learn how to ask questions! Next we'll learn that your HTML is displayed in a notification bubble on Windows Mobile and you want to run a batch file on a desktop connected to it via ActiveSync :)
@sushant -- i don't know VB, but to accomplish your task you just need to enclose your variable value in quotes and append it to the command line. Something like this: shell.run "c.bat " + """ + x + """, though i don't know how string concatenation is written in VB
well actually i was trying two approaches: calling two batch files by vbs and 2nd-calling a batch file which subsquently calls the required batch files. since my whole tool is developed in vbs, so the path entered would be there too. so i was trying to pass that path to the batch files through vbs only. i am sorry for altering my questions. i am a beginner, so i am trying 2-3 approaches, and so asking questions on those approaches.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.