Open URL that contains umlaut with batch

我的未来我决定 提交于 2021-02-04 08:11:50

问题


I want to open an URL in chrome with a batch file. This works for normal URLs, but it doesn't for URLs with umlauts.

start chrome.exe https://trends.google.de/trends/explore?q=mähroboter

I cannot use "ae" as a replacement for "ä", as it will give me different results on Google Trends.

When I keep it like this, the URL in my browser changes to

https://trends.google.de/trends/explore?q=mA4hroboter

which again gives me the wrong results. It needs to be "ä".

I tried playing around with the file encoding. Currently UTF8 without BOM. I tried UTF8 with BOM, ANSI, converting to and fro. Nothing seemed to work. What can I do to make it work?


回答1:


URLs must be URL encoded with percent-encoded bytes.

That means the German umlaut ä in a URL must be first UTF-8 encoded with the two bytes with the hexadecimal values C3 A4 and next percent-encoded resulting in %C3%A4 in the URL string:

https://trends.google.de/trends/explore?q=m%C3%A4hroboter

In a batch file a percent sign must be escaped with an additional percent sign to get it interpreted by Windows command processor as literal character and not

  • as beginning of a batch file argument reference as explained by help of command CALL output on running call /? in a command prompt window, or
  • beginning of a loop variable reference as explained by help of command FOR output on running for /? in a command prompt window, or
  • beginning / end of an environment variable reference as explained by help of command SET output on running set /? in a command prompt window.

So in the batch file must be used:

start chrome.exe https://trends.google.de/trends/explore?q=m%%C3%%A4hroboter


来源:https://stackoverflow.com/questions/52026786/open-url-that-contains-umlaut-with-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!