none
UTF-8 characters (e.g À ) are not supporting in batch file RRS feed

  • Question

  • I am trying to add user using batch file, I have used UTF-8 characters in username. I am trying below command net user Àdmin "sdf" /ADD /FULLNAME:Àdmin /COMMENT:"description" I observed that user added successfully but if i see local users then is shows ├Çdmin in place of Àdmin.

    If I run the above command manually on cmd it is working as per expected but it is not working if i execute this command using bat file.

    It looks like limitation of bat.

    I have gone though few forums and found that this could be the problem of DOS version.

     

    I am using 6.1.7600 DOS version.

    Could anybody help on this.

     

    Thanks,

     

     

     

    Thursday, June 9, 2011 7:45 AM

Answers

  • I may not have answered your question, however, which involves three components: the batch file, the command processor, and the program interpreting the command line. The following commands in a batch file do produce a new account with the expected values on my test system:

    chcp 1252
    net user Àdmin "sdf" /ADD /FULLNAME:Àdmin /COMMENT:"description"

    Thursday, June 9, 2011 8:32 PM

All replies

  • Hi,

    Just FYI, there is no DOS in Windows 7 (or any other flavor of NT, for that matter). You are talking about Cmd.exe, which is a Win32 console (text-mode) program.

    IIRC, shell scripts (.bat or .cmd files) must be ASCII format. Unicode and UTF-8 text files are not supported.

    Bill

    Thursday, June 9, 2011 6:44 PM
    Moderator
  • Use the chcp command to change the active code page:

    @rem foo.bat
    
    @echo off
    
    chcp 1252
    
    echo À
    
    
    
    C:\> foo.bat
    
    À
    
    

    A complete list of code pages is published at http://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx. I don't believe the command prompt works properly with Unicode code pages like UTF-8, but I'm probably wrong. In a quick test, I couldn't run batch files, regardless of the format, with the code page set to 65001 (UTF-8). Code page 1252 definitely displays "À" correctly. Hopefully, there are others in the forum with more experience with multilingual Windows systems.


    • Proposed as answer by Trevor Scroggins Friday, June 10, 2011 12:26 AM
    • Edited by Trevor Scroggins Friday, June 10, 2011 4:59 PM modified URL to use http://msdn... instead of http://technet...
    Thursday, June 9, 2011 8:29 PM
  • I may not have answered your question, however, which involves three components: the batch file, the command processor, and the program interpreting the command line. The following commands in a batch file do produce a new account with the expected values on my test system:

    chcp 1252
    net user Àdmin "sdf" /ADD /FULLNAME:Àdmin /COMMENT:"description"

    Thursday, June 9, 2011 8:32 PM
  • Hi Bill,

     

    Thanks for the response.

    I am using Windows2008 R1 , R2 and Windows 2003 servers. Yes you are true i was talking about cmd.exe version.

    Could you please guide me, How can I provide support to UTF-8 characters on bat file. I am wondering if there is way which Microsoft provide to support UTF-8 characters.

     

    Thanks,

    Dinesh

    Friday, June 10, 2011 6:00 AM
  • Hello,

    Thanks for the response. Please look below screenshot.

     

    I have created bat file and put the command , Now when i execute the bat file it is not able to understand UTF-8 character appropriately.

    Could you please guide me, If there is any other way to handle it.

     

    Thanks,

    Dinesh

    Friday, June 10, 2011 6:08 AM


  • I am not able to paste screenshot here.but after using solution suggested by you ,its not working.

    Could you please guide if there is any other way to do this.

     

    Thanks,

    Dinesh

    Friday, June 10, 2011 6:16 AM
  • Hi Dinesh,

    The batch processor expects 8-bit ASCII files, not 16-bit UTF-8 files as created by Notepad and other applications. If you need to support scripts in a Unicode environment, I suggest using PowerShell.

    Friday, June 10, 2011 5:18 PM
  • chcp 65001 helped me to run UTF-8 batches

    example for unicode character ⬥:

    chcp 65001
    C:\Tools\Code128\Code128Gen.exe 0 "aCLa" 2 D:\Out\128_N2T60_⬥CL⬥.bmp
    C:\Tools\Code128\Code128Gen.exe 0 "aCLAa" 2 D:\Out\128_N2T60_⬥CLA⬥.bmp


    Important:

    if your .bat file begins with BOM mark, remove it (switch the encoding to "UTF-8 without BOM") otherwise the interpreter will complain about first line of your batch, for example:

    C:\Tools\Code128>´╗┐chcp 65001
    '´╗┐chcp' is not recognized as an internal or external command,
    operable program or batch file.

    After some time, original UTF-8 batch file stopped working normally at commands which contained non-ascii characters. Commands were executed normally as before (producing correct output), but this misformatted message was shown at output of each:

    C:\Tools\Code128>C:\Tools\Code128\Code128Gen.exeThe system cannot write to the specified device.





    • Edited by Miroxlav Saturday, February 7, 2015 12:49 PM
    Saturday, February 7, 2015 12:15 PM