Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to convert a batch file stored in utf-8 to something that works via another batch file and run it
    primarykey
    data
    text
    <p>I have a program I use to create a batch file. My problem is that the program's output is UTF-8 so as soon as any diacritical marks like é,à,ö,Ä are in my batch file it fails. It seems I can't figure out a way to convert my output to anything but UTF-8 in the program that creates the batch file. </p> <p>So I was thinking of creating two bach files. The actual one and another that converts the actual one from UTF-8 to ANSI (Windows Codepage 1252, or maybe cp 850) and then executes it after that. Of course I'd add a chcp xxxx as the first command of the actual batch file.</p> <p>So my question is is there an alternative to iconv on Windows - or how does one convert a UTF-8 text file to a windows codepage using a second batch file. Is there anything built into Win XP and up that I could use or is there a free and redistributable tool I might use for this?</p> <p>Note:</p> <pre><code>chcp 65001 </code></pre> <p>does not work for batch files.</p> <p><strong>EDIT 1:</strong></p> <p>on windows XP I created two batch files to test the first answer.</p> <p>1.bat encoded to UTF-8 without BOM contains:</p> <pre><code>chcp 1252 cd üöä </code></pre> <p>2.bat also encoded to UTF-8 without BOM - but without any special characters contains:</p> <pre><code>chcp 1252 type "1.bat" &gt;"ansi_file.bat" </code></pre> <p>The resulting ansi_file.bat created when one executes 2.bat will still be utf-8 encoded and not ansi encoded.</p> <p><strong>EDIT 2:</strong></p> <p>The mentioned reverse process works.</p> <pre><code>chcp 1252 echo ü &gt; ansi.txt cmd /u /c type ansi.txt &gt; unicode.txt </code></pre> <p>but neither of the following subsequent lines</p> <pre><code>cmd /a /c type unicode.txt &gt; back2ansi.txt type unicode.txt &gt; back2ansi_v2.txt </code></pre> <p>gets me back to ANSI. I tried this both on Win XP and Win 7. Can anyone help?</p> <p><strong>NOTE:</strong></p> <p>I'm aware of how to use the Windows Script Host and VBS. I'd like to avoid depending on the script host though. The VBS method is detailed here: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa368046%28v=vs.85%29.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/aa368046%28v=vs.85%29.aspx</a></p> <p><strong>EDIT 3:</strong></p> <p>The text file created containing a unicode ü above is not utf-8</p> <p>The Windows unicode file is HEX:</p> <pre><code>FC 00 20 00 0D 00 0A 00 </code></pre> <p>UTF-8 without BOM would be HEX:</p> <pre><code>C3 BC 20 0D 0A </code></pre> <p>The VBS solution linked to only works with the unicode form but fails on the UTF-8 form. I need to convert UTF-8 to another code page so not even that one seems to work for me...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload