How do you pass a variable (or possibly more than one) to a called batch script?
An example of what I am trying to do is(in sudo code where // signifies a comment):
DriveLetter=E:
//assigns the value E: to variable DriveLetter
OS =call "GetOS.bat" \DriveLetter
//Returns either V for Vista, X for XP, 7 for Windows 7, or 0 if no OS is found on the
//drive DriveLetter wich in this case would be E:
//(I don't need the code for how to do this check, just how to pass the variable to and from)
if OS != 0 DO call "Cleanup%OS%.bat" \DriveLetter
//Runs one of 3 cleanup scripts name CleanupX.bat CleanupV.bat and Cleanup7.bat
//on the drive DriveLetter
I hope what I am trying to accomplish is clear, if not I would be more than happy to elaborate...
Page 1 of 1
Passing a variable to and returning a value from a called batch script
#2
Posted 10 February 2010 - 10:59 AM
The arguments are taken as %1 %2 %3 and so on inside the called batch file.
Example:
Create a batch file sample.bat with following contents : @echo Hello %1. Your age is %2 years.
Now in the command prompt pass arguments like this: sample.bat Billy 16
This would produce an output like : Hello Billy. Your age is 16 years.
Example:
Create a batch file sample.bat with following contents : @echo Hello %1. Your age is %2 years.
Now in the command prompt pass arguments like this: sample.bat Billy 16
This would produce an output like : Hello Billy. Your age is 16 years.
Share this topic:
Page 1 of 1

Help

Back to top









