Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30-07-2009
Member
 
Join Date: Apr 2009
Posts: 9
Variables in .bat files

I need the .bat file variables explanation? How to use the variables in bat file, How to pass variables between batch files? Thanks in advance for help.
Reply With Quote
  #2  
Old 30-07-2009
Member
 
Join Date: Mar 2008
Posts: 198
Re: Variables in .bat files

By using the below code you can output as many many variables as you like:


Quote:
CProgram]
#include

main() {
printf("BatchFile.bat %d",ReturnValue);
}
[End CProgram]
Quote:
[BatchFile.bat]
@echo off
if not (%1)==() goto Var
echo @echo off >tmp.bat
CProgram.exe >> tmp.bat
tmp.bat
:Var
set XVar=%1;
del tmp.bat
[End BatchFile.bat]
Reply With Quote
  #3  
Old 30-07-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Variables in .bat files

Special variables in Windows Batch files


Quote:
rem special variables for batch files

@echo off


echo fully qualified name of this batch file:

echo %~fn0


echo path to here:

echo %~dp0


echo arguments passed (if any):

echo %*
Reply With Quote
  #4  
Old 30-07-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Variables in .bat files

In DOS batch files, you can create and use variables. The variables are expressed using the percentage symbol followed by a number. For example, look at the following batch file, which I will call test.bat:
Quote:
@Echo off
dir% 1
This is a very simple batch file, but here is how you can use. At the prompt, type (I'm assuming you are working in the folder C: \ DOSTEMP \ working directory):
Quote:
c:\dostemp\>test.bat c:\
If you have done correctly, you should see a complete directory listing in the root directory of C: What is the batch file to take the command DIR and its application to any specified directory. If you neglect to specify a directory, you will get a listing of the current working directory (C: \ DOSTEMP \), as if he had given a DIR command, without specifying the destination directory. If you specify a directory on the command line, which is the directory variable 1, or 1%. Now, I suppose, that had issued the command:

Quote:
c:\dostemp\>test.bat c:\ c:\windows\
If you try this, you will see that you still get the list of the root directory of C:, but only that. After all, your batch file is looking for a variable, and the DIR command can have only one directory.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Variables in .bat files"
Thread Thread Starter Forum Replies Last Post
State variables in ASP.net Athreya Software Development 3 12-01-2011 01:15 PM
What are the Predefined Variables in PHP? Leonard Software Development 5 27-02-2010 11:44 PM
What are an Environment Variables in PHP? N I C K Software Development 5 21-02-2010 01:29 AM
What are the PHP Variables? shivendra Software Development 5 28-01-2010 07:05 PM
Replace variables in php John Wilson Software Development 3 04-12-2009 02:17 PM


All times are GMT +5.5. The time now is 12:21 AM.