views:

243

answers:

1

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?

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

atzz
this puts destination path in %1. right?
sushant
@sushant: Yes, it does.
Joey
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?
sushant
i've edited my sample to include a variable
atzz
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
@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 :)
atzz
@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
atzz
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.
sushant
well in vbscript it works if i use :shell.run "c.bat D:\d" and then receive this in c.bat as %1. but what i need is to pass a variable which contains the path. i.e if x contains the path, i want to pass x
sushant