Command line argument from batch file containing U

2019-04-12 07:33发布

I wrote a little utility that takes a path as a command line argument, but I am running into trouble if (and only if) that argument is passed from a batch file and contains UTF-8 characters like Umlauts (which is unfortunately rather common when the system language is german).

I can pass a file name with Umlaut from the projects debug properties, no problem. I can pass a file name with Umlaut from the command line, no problem. I pass a file name with Umlaut from a batch file, mayhem.

Obviously, I have tried saving the batch file UTF-8 encoded... but then the darn thing won't execute any commands whatsoever.

The actual program is written in C#. What options do I have to process these arguments correctly, either in the batch file or code-side?

2条回答
时光不老,我们不散
2楼-- · 2019-04-12 08:12

Use CHCP 1252 as the first line of your batch and it will work with paths.

Edit: Just tested it. It will work. Parameters are working where getting the right output (by echo) wont.

Anyway, if you try to echo out something like "öäü" it will not be displayed correctly.

To fully get around it, get yourself an editor which is able to save your file in ASCII-Encoding (notepad++ cant from my knowledge).

查看更多
等我变得足够好
3楼-- · 2019-04-12 08:13

you can use PowerShell scripts for UTF 8.The batch processor supports ASCII files only.

查看更多
登录 后发表回答