BleepingComputer.com: Passing a variable to and returning a value from a called batch script

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Passing a variable to and returning a value from a called batch script

#1 User is offline   Will B. 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 5
  • Joined: 09-February 10

Posted 09 February 2010 - 12:35 PM

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

#2 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

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.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users