过滤 Windows 批处理文件中的参数
是否可以过滤 Windows 批处理文件中的参数列表?
假设它的调用方式如下:
file.cmd arg1 --unwanted arg3
它应该调用一些其他可执行文件(硬编码),而不带参数字符串--unwanted
:
some.exe arg1 arg3
我只知道参数的名称,它可以作为列表中的任何参数传递。它可能不存在于参数列表中,并且所有参数都应未经修改地传递。参数的数量可能会有所不同。
更多示例(什么叫 -> 在结果中应该叫什么)
file.cmd arg1 arg2 -> some.exe arg1 arg2
file.cmd --unwanted -> some.exe
file.cmd --unwanted arg2 -> some.exe arg2
file.cmd arg1 --unwanted -> some.exe arg1
从 unix shell 脚本编写 Windows 批处理文件对我来说是黑魔法:)
Is it possible to filter list of arguments in windows batch file?
Assuming it is called like:
file.cmd arg1 --unwanted arg3
It should call some other executable (hardcoded) without the argument string --unwanted
:
some.exe arg1 arg3
I only know the name of the argument, it can be passed as any argument in the list. It may not exist on argument list, and the all arguments should be passed unmodified. Number of arguments may vary.
More examples (what's called -> what should be called in result)
file.cmd arg1 arg2 -> some.exe arg1 arg2
file.cmd --unwanted -> some.exe
file.cmd --unwanted arg2 -> some.exe arg2
file.cmd arg1 --unwanted -> some.exe arg1
Moving from unix shell scripting windows batch files are black magic to me :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
打印:
编辑:
打印的
意思是“arg1=foo”已损坏,您可以将 for 循环切换到
for /F "tokens=%var% delims= " %%A in (' echo.%*') do (
让它工作,但这会破坏 arg1=foo 和 arg3="bar"这是批处理文件的一个已知问题,一旦你开始弄乱字符串,事情就会搞砸在某些配置中,因为总是有一些字符会弄乱事情(%,!,“,^,&,|,<,>,空格等)
This prints:
Edit:
prints
meaning "arg1=foo" is broken, you can switch the for loop to
for /F "tokens=%var% delims= " %%A in ('echo.%*') do (
to get it working, but that breaks arg1=foo and arg3="bar"This is a known problem with batch files, once you start messing with strings things are going to get screwed up in some configuration since there is always some character that is going to mess things up (%,!,",^,&,|,<,>,space etc)