本文介绍了问号获取在 Windows 批处理文件中编码的 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在处理几天前可以使用的批处理脚本时遇到问题,但现在无法使用,即使没有进行任何更改!我认为系统中发生了一些在我不知情的情况下发生的变化.

I'm having trouble with a batch script that worked a few days ago, but now doesnt work, even though no changes has been made!I believe something has changed in the system without my knowledge.

预期的链接是:

order.htm?order=12345

但它变成了这样:(注意问号变成了 %3F)

But it becomes like this: (notice the question mark becomes %3F)

order.htm%3Forder=12345

代码如下:

@echo off
echo.

set "drive=%~d0"
set "runningDir=%~dp0"

:start
ClS
Echo.
Set /P Job=Enter number:^>

@echo off

if exist c:\"Program Files (x86)"\Google\Chrome\Application\chrome.exe goto program_files_x86

:program_files_x86
start c:\"Program Files (x86)"\Google\Chrome\Application\chrome.exe --disable-print-preview --ignore-certificate-errors --disable-web-security --user-data-dir --allow-file-access-from-files %runningDir%\order.htm?order=%job%
goto end

:end
goto start

有什么建议吗?

最好的问候尼古拉斯

推荐答案

通常应该在整个文件夹/文件字符串周围使用双引号,而不仅仅是其中的一部分.

Double quotes should be usually used around entire folder/file string and not just parts of it.

Command START 将第一个双引号字符串解释为新命令进程的标题.因此,在启动 GUI 应用程序时,应在 START 命令行上使用由 "" 指定的空标题字符串,以避免将双引号文件名解释为要执行的应用程序的路径作为标题字符串.

Command START interprets first double quoted string as title for the new command process. Therefore on starting a GUI application an empty title string specified with "" should be used on START command line to avoid interpreting the double quoted file name with path of the application to execute as title string.

%~dp0 引用的批处理文件路径总是以反斜杠结尾.因此,不要在此字符串或带有批处理文件路径的环境变量(如 runningDir )后指定额外的退格.顺便说一句:运行批处理文件的当前目录可以与批处理文件的目录不同.出于这个原因,名称 runningDir 并不具有误导性.环境变量的更好名称是 BatchPath.

The batch file path referenced with %~dp0 always ends with a backslash. Therefore don't specify an extra backspace after this string or an environment variable like runningDir with path of batch file. By the way: The current directory on running a batch file can be different to directory of batch file. For that reason the name runningDir is not good as misleading. A better name for the environment variable is BatchPath.

可以在批处理文件中使用 start 作为标签.但是不建议这样做,因为命令 START 使得搜索标签和搜索命令变得困难.最好使用像 Begin 这样的标签.

It is possible to use start as label in a batch file. But it is not advisable to do that because of command START which makes it difficult to search for label respectively search for command. It is better to use a label like Begin.

在 url 中,目录分隔符是 /,因此批处理文件路径中的每个反斜杠(Windows 上的目录分隔符)都应替换为斜杠.

In an url the directory separator is / and therefore each backslash (directory separator on Windows) in batch file path should be substituted by a slash.

网址应以http://(超文本传输​​协议)等协议开头,并应完全用双引号括起来.

The url should start with the protocol like http:// (Hypertext Transfer Protocol) and should be enclosed completely in double quotes.

最后一个 echo/echo(echo. 打印空行要好,参见 Echo [特殊字符] 之间的区别 详情.

And last echo/ or echo( is better than echo. for printing a blank line, see Difference between Echo[Special Character] for details.

重写的批处理代码:

@echo off
echo/

set "BatchPath=%~dp0"
set "BatchPath=%BatchPath:\=/%"

:Begin
clS
echo/
set /P "Job=Enter number: "

if exist "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" goto program_files_x86

:program_files_x86
start "" "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" --disable-print-preview --ignore-certificate-errors --disable-web-security --user-data-dir --allow-file-access-from-files "http://%BatchPath%order.htm?order=%Job%"
goto end

:end
goto Begin

要了解使用的命令及其工作原理,请打开命令提示符窗口,在那里执行以下命令,并仔细阅读为每个命令显示的所有帮助页面.

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • cls/?
  • echo/?
  • 转到/?
  • if/?
  • set/?
  • 开始/?

这篇关于问号获取在 Windows 批处理文件中编码的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 20:20