Results 1 to 4 of 4

Thread: Variables in .bat files

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

  2. #2
    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:


    CProgram]
    #include

    main() {
    printf("BatchFile.bat %d",ReturnValue);
    }
    [End CProgram]
    [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]

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Variables in .bat files

    Special variables in Windows Batch files


    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 %*

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    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:
    @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):
    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:

    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.

Similar Threads

  1. State variables in ASP.net
    By Athreya in forum Software Development
    Replies: 3
    Last Post: 12-01-2011, 01:15 PM
  2. What are the Predefined Variables in PHP?
    By Leonard in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 11:44 PM
  3. What are an Environment Variables in PHP?
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 21-02-2010, 01:29 AM
  4. What are the PHP Variables?
    By shivendra in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 07:05 PM
  5. Replace variables in php
    By John Wilson in forum Software Development
    Replies: 3
    Last Post: 04-12-2009, 02:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,905,997.35241 seconds with 17 queries