none
Help with a simple FOR /F loop in Batch file RRS feed

  • Question

  • Hello, I'm having an issue with a simple FOR loop in a batch file. According to the FOR command's syntax (Microsoft's Technet on FOR), this loop should read & echo each line of iwov.txt, but instead the loop doesn't run.  I'm aware that the TYPE command will do the same thing but my goal is to export, alter, & import this registry key, I just haven't gotten that far yet. Could someone help me figure out what's wrong with this loop?

    SetLocal EnableDelayedExpansion
    cd /d c:\deleteme\
    reg export HKLM\SOFTWARE\Wow6432Node\Interwoven\Worksite\8.0\FileSite\Commands\Document iwov.txt /y
    for /f "tokens=*" %%n in (C:\deleteme\iwov.txt) do (
        set rdln=%%n
        echo !rdln!
    )


    Contents of C:\deleteme\iwov.txt :

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\Software\Wow6432Node\Interwoven\WorkSite\8.0\FileSite\Commands\Document]
    "Commands"="iManExt3.NewOpenCmd,iManExt.OpenROCmd,iManExt.PrintCmd,iManExt.ViewCmd"

    Batch File Output:

    c:\>c:\deleteme\tech.bat

    c:\>SetLocal EnableDelayedExpansion

    c:\>cd /d c:\deleteme\

    c:\deleteme>reg export HKLM\SOFTWARE\Wow6432Node\Interwoven\Worksite\8.0\FileSite\Commands\Document iwov.txt /y
    The operation completed successfully.

    c:\deleteme>for /F "tokens=*" %%n in (C:\deleteme\iwov.txt) do (
    set rdln=%%n
    echo !n!
    )

    c:\>

    Tuesday, February 25, 2014 9:10 PM

Answers

  • The output from export is Unicode.  Batch does not understand how to parse Unicode files.


    ¯\_(ツ)_/¯

    • Marked as answer by tuxOnWindows Wednesday, February 26, 2014 4:32 PM
    Wednesday, February 26, 2014 4:19 PM

All replies

  • Works fine for me.  Try it against a file that is just plain text.


    ¯\_(ツ)_/¯

    Wednesday, February 26, 2014 4:17 PM
  • The output from export is Unicode.  Batch does not understand how to parse Unicode files.


    ¯\_(ツ)_/¯

    • Marked as answer by tuxOnWindows Wednesday, February 26, 2014 4:32 PM
    Wednesday, February 26, 2014 4:19 PM
  • Here is the Unicode work-around:

    for /f %%n in ('type C:\deleteme\iwov.txt') do (
        setrdln=%%n
        echo !rdln!
    )


    ¯\_(ツ)_/¯

    Wednesday, February 26, 2014 4:25 PM
  • Thank you, this has been driving me crazy over the past few days because I've used the same exact code in other batch files that work. I tested a plain text file before my first post & it failed, but that was due to inserting plain text into the exported file and saving it as something else, which kept the encoding as Unicode.
    Wednesday, February 26, 2014 4:37 PM