7267

passing variable to a batch file when called using “call” function

Question:

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.<br /> 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?

Answer1:

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.

Recommend

  • ANTLR4: Extraneous Input error
  • How to make one column to take all the remaining width?
  • why am I stuck in an infinite loop after invoking poll() or remove() on a priority queue? Java
  • Batch file read in var and write back
  • WCF Service Application returns 404 using WebGet
  • Determining if a string has been entered with a leading single quote
  • Type mismatch: cannot convert from Connection to Connection
  • Drag and Drop for imageview not working
  • iOS Localization Doesn't Work with More Than 63 Files
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • Google Maps api v3 get start and end coordinates of a street
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Assign variable to the value in HTML
  • Keep this build forever option - Jenkins
  • How to use carriage return with multiple line?
  • Converting a WriteableBitmap image ToArray in UWP
  • Swift: Switch statement fallthrough behavior
  • How to test if a URL from an Eclipse bundle is a directory?
  • Paperclip, set path outside of rails root folder
  • QLineEdit password safety
  • Is there any way to access browser form field suggestions from JavaScript?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • script to move all files from one location to another location
  • ILMerge & Keep Assembly Name
  • Running a C# exe file
  • Perl system calls when running as another user using sudo
  • Symfony2: How to get request parameter
  • Hazelcast - OperationTimeoutException
  • Google cloud sdk not working when python points python3
  • Why winpcap requires both .lib and .dll to run?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • Authorize attributes not working in MVC 4
  • Append folder name and increment by 1 using batch script
  • Busy indicator not showing up in wpf window [duplicate]
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF