有关在Windows上使用xargs运行批处理脚本的问题

问题描述

使用xargs在Windows上运行批处理脚本时遇到问题。为了说明问题,我创建了一个测试输入文件testinput.txt,其中包含由NUL分隔的test\file.txt的16K副本和一个包含{p>

mytest.bat

然后我跑了@echo off @echo %* cat input.txt | xargs -t -0 .\mytest.bat命令将xargs作为.\mytest.bat运行了多次。但是,除最后一个命令外,所有'.\mytest.bat' 'test\file.txt' 'test\file.txt' ...命令都以

失败
.\mytest.bat

我怀疑这是因为批处理脚本行的长度受Windows The command line is too long. 的最大命令行长度8191的影响(请参阅Command prompt (Cmd.exe) command-line string limitation)。运行Windows批处理脚本时,cmd.exe是否应该考虑xargs的最大命令长度?

然后我运行cmd.exe将命令限制为8191个字符。但是,cat input.txt | xargs -s 8191 -t -0 .\mytest.bat生成的命令长于8191个字符。在计算命令长度时,也许xargs不在计算它添加的引号(')。这是xargs的bug还是这里发生的其他事情?而且,至少在运行批处理脚本时,xargs是否应该在Windows上使用双引号(“)而不是单引号(')来引号命令参数(请参见What does single-quoting do in Windows batch files?)?

我正在使用 Windows 10 git版本2.27.0.windows.1 随附的 xargs(GNU findutils)4.7.0 >。我应该使用Windows的另一个xargs实现代替吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)