Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 调用:ProcessArgs/?生成呼叫帮助,而不是使用“/”调用:ProcessArgs&引用;_Batch File - Fatal编程技术网

Batch file 调用:ProcessArgs/?生成呼叫帮助,而不是使用“/”调用:ProcessArgs&引用;

Batch file 调用:ProcessArgs/?生成呼叫帮助,而不是使用“/”调用:ProcessArgs&引用;,batch-file,Batch File,我有一个处理一些命令行选项的脚本,我希望它也能处理/?和-?。后者很好,但是当我使用/?我得到了呼叫帮助,但从未调用过子程序。我在这里做了一些搜索,但是在这么多的结果中找不到任何与这个问题相关的东西 以下是最简单的方法,我可以将其简化为: @setlocal ENABLEEXTENSIONS @set prompt=$G call :ProcessArgs %* @exit /b 0 :ProcessArgs @echo %* @exit /b 0 当用-?一切都很好,但是?结果: &g

我有一个处理一些命令行选项的脚本,我希望它也能处理/?和-?。后者很好,但是当我使用/?我得到了呼叫帮助,但从未调用过子程序。我在这里做了一些搜索,但是在这么多的结果中找不到任何与这个问题相关的东西

以下是最简单的方法,我可以将其简化为:

@setlocal ENABLEEXTENSIONS
@set prompt=$G

call :ProcessArgs %*

@exit /b 0

:ProcessArgs
@echo %*
@exit /b 0
当用-?一切都很好,但是?结果:

>call :ProcessArgs /?
Calls one batch program from another.

CALL [drive:][path]filename [batch-parameters]

batch-parameters   Specifies any command-line information required by the
                 batch program.
...
这对我来说似乎是一个bug,但我怀疑我是否会在我的Win10框的cmd.exe中发现任何新bug。在%*左右使用引号可以避免帮助溢出,但也会导致:ProcessArgs接收单个参数,这是我绝对不希望发生的

任何线索或解决办法都将不胜感激


谢谢。

这是一个bug,但可以用作功能()

在您的情况下,您可以通过使用双百分比来避免这种行为

Set "args=%*"
call :ProcessArgs %%args%%"

我对您的示例脚本做了两个微小的更改,它适用于Windows 7下的
/?

@setlocal ENABLEEXTENSIONS
@set prompt=$G

call :ProcessArgs %%*

@exit /b 0

:ProcessArgs
@echo(%*
@exit /b 0

对于通配符参数修饰符
%*
,Jeb关于使用双百分比转义的观点似乎是正确的。需要对
@echo
进行一个小的更改,以防止
echo
喷出其
帮助

CMD充满了bug和惊喜;事实上,我确实认为你已经发现了一个新的特性(女士对“bug”的行话)。这似乎是我从未想到过的答案。非常感谢。除非稍后有更好的答案,否则我会记下这个。非常好。最好使用
echo(
而不是
echo[
),因为在一些模糊的情况下
echo[
可能会失败。