+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Batch: Text file -> Environment variable? in Coding and Web Development; Have an INI file with contents like: Code: Alice=One2Three Bob=Four5Six I want to pick one entry e.g. Bob and put ...
  1. #1

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    116

    Batch: Text file -> Environment variable?

    Have an INI file with contents like:

    Code:
    Alice=One2Three
    Bob=Four5Six
    I want to pick one entry e.g. Bob and put it in an environment variable. This works:

    Code:
    for /f "usebackq tokens=2 delims==" %%i in (`findstr Bob file.ini`) do set Bob=%%i

    Took me a teensy while to arrive there having first failed with other approaches. Has anyone ever got "other approaches" to work or is this pretty much what you have to do?

  2. #2

    Join Date
    Feb 2006
    Location
    Derbyshire
    Posts
    1,381
    Thank Post
    181
    Thanked 211 Times in 171 Posts
    Rep Power
    66

    Re: Batch: Text file -> Environment variable?

    That's pretty much exactly how I'd do it... What other approaches did you try? Would be interesting to see if there's anything which could be hacked around a bit another time.

  3. #3

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,682
    Thank Post
    755
    Thanked 1,715 Times in 1,526 Posts
    Rep Power
    438

    Re: Batch: Text file -> Environment variable?

    Simple and works seems like a winner to me.

    Ben

  4. #4

    bossman's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    4,033
    Thank Post
    1,262
    Thanked 1,107 Times in 785 Posts
    Rep Power
    338

    Re: Batch: Text file -> Environment variable?

    So if tom, Dick and Harry each had their own variables would it work as good hehe

  5. #5

    Join Date
    Oct 2005
    Location
    West London
    Posts
    55
    Thank Post
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Batch: Text file -> Environment variable?

    Nice bit of code.
    I'm getting to grips with AutoIt - that has specific functions for reading / writing .INI files. I recommend it.
    Or you could use a separate initool.exe such as this:- http://www.jsifaq.com/SF/Tips/Tip.aspx?id=7373

  6. #6

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    116

    Re: Batch: Text file -> Environment variable?

    What other approaches did you try?
    Oh I had loads of fun trying and failing to pipe and redirect the output of 'find' or 'findstr' to 'set' etc.

    Suspect my heart is stuck in early DOS days because "for /f.." just feels more complicated.



SHARE:
+ Post New Thread

Similar Threads

  1. Rename a PC from a batch file - Any ideas?
    By MrLudwig in forum Windows
    Replies: 13
    Last Post: 8th December 2007, 03:40 AM
  2. batch file to shutdown PCs
    By macca in forum Windows
    Replies: 5
    Last Post: 3rd May 2007, 10:20 AM
  3. prezzie batch file to collect dps logs
    By russdev in forum ICT KS3 SATS Tests
    Replies: 4
    Last Post: 16th May 2006, 01:16 PM
  4. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 08:48 PM
  5. URLblacklist.com as text file
    By adamyoung in forum How do you do....it?
    Replies: 11
    Last Post: 9th February 2006, 03:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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