Results 1 to 3 of 3
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,416
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Controlling Vars from batch files

    Update:

    I tried this also using a basic set command:

    set lfBrowser =
    set lfBrowser %cpBrowser%

    This works fine -- the first time. The second time however

    set lfBrowser =
    set lfBrowser %pmBrowser%

    lfBrowser has remained at %cpBrowser%.

    Must I reboot any time I change a variable?

    CB
    ---
    I can set a variable in a batch file using

    C:\Windows\system32\setx.exe VarOne=%varInfo%

    But then if I run the same command but changing varInfo to varInfo2

    C:\Windows\system32\setx.exe VarOne=%varInfo2%

    VarOne stays at the original value [varInfo].

    What am I doing wrong here?

    Regards,
    Chuck Billow
    Last edited by CWBillow; 2013-07-02 at 16:08.
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,517
    Thanks
    54
    Thanked 1,038 Times in 966 Posts
    Environment variables change as soon as you tell them to, but only for the current session. .e.g Set the value in a DOS box, then read it in a second DOS box and it will not have changed.

    Please tell us exactly what you are doing or post a screen shot?

    cheers, Paul

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,472
    Thanks
    34
    Thanked 197 Times in 177 Posts
    set lfBrowser =
    set lfBrowser %pmBrowser%


    The second SET command should fail because you have omitted the = sign.

    The code should be simply:
    set lfBrowser=%pmBrowser%

    Setting the variable to empty/undefined in the previous statement is redundant.

    It's also a good idea to get out of the habit of leaving blanks before and after the equals sign, because these can give unexpected results. What you are actually doing is setting a variable named IfBrowser# where # represents a blank character!

    For example, see the results of
    set var = 12345
    echo variable var (surrounded by square brackets) is [%var%]


    gives
    variable var (surrounded by square brackets) is []

    Whereas
    set var = 12345
    echo variable var (surrounded by square brackets) is [%var %]


    gives
    variable var (surrounded by square brackets) is [ 12345]

    Observe that what I was actually doing was setting a variable with the name "var " (blank character after var...)

    I could have obtained the same results using
    set "var "= 12345

    And remember ECHO is your friend!
    Last edited by BATcher; 2013-07-04 at 10:13.
    BATcher

    "The trouble with quotes on the internet is that you can never know if they are genuine."
    Abraham Lincoln
    

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •