拆分传递的参数,然后访问所有元素 [英] Split the passed parameter, then access all elements
问题描述
我的.bat文件应该执行作为第一个参数,%1,这需要的是包含传递的第二个参数中的参数,%2列表传递命令。
My .bat file is supposed to execute command passed as the first argument, %1, which takes a list of parameters that are contained within the second parameter passed, %2.
请注意第二个文件是PTED作为句子间$ P $,但实际上是单词的列表。因此,节目%1抱怨,因为它只能访问一个元素。我怎么可以拆分第二个参数,2%,并调用正确的格式%1%firstArgOf1%secondArgOf1 ...
Note that the second file is interpreted as a sentence, but is in fact a list of words. Therefore, program %1 complains as it has access to only one element. How can I split the second argument, %2, and invoke the correct format %1 %firstArgOf1 %secondArgOf1 ...
我感兴趣的是解决方案的地方的话在2%的数量是事先知道,但在2%与未知字数的一个变种是值得欢迎的。
I am interested in solutions where the number of words in %2 is know in advance, but a variant with an unknown number of words in %2 is welcome.
例如:
程序myProgram接受6个参数。参数任何其他数字传递一个错误的结果:
Program "myProgram" accepts 6 parameters. Any other number of parameters passed results in an error:
myProgram "this is one sentence passed as a single parameter"
不过,myProgram正常工作在以下内容:
However, myProgram works correctly in the following:
myProgram this is one sentence passed as a single parameter
问题是,参数这是作为一个单独的参数传递了一句传递AA字符串(这是固定的),所以我必须要找到一个.bat文件拆分此参数的解决方法。
The thing is, parameter "this is one sentence passed as a single parameter" is passed a a string (and this is fixed), so I have to find a workaround in a .bat file to split this argument.
推荐答案
要从一个参数报价删除,你可以使用语法%〜1
。
To remove quotes from a parameter, you can use the syntax %~1
.
在一个批处理文件,它看起来像
In a batch file it looks like
@echo off
myProg.exe %~1
这篇关于拆分传递的参数,然后访问所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!