1
在批处理文件中,我想将一个变量设置为程序的单行输出 - 这是一个在多个问题和互联网资源中解释的任务。对于/ F:文件名和参数中的空格
在我具体的任务,我想执行的命令
"D:\__My Program\___My Program\Folder1\Folder2\..\..\FileVersion\FileVersion\bin\Release\FileVersion.exe" /n "D:\__My Program\___My Program\Folder1\Folder2\bin\Deploy\My Program.exe"
正如你所看到的,因为我要执行的程序路径,FileVersion.exe
包含空格,并交给FileVersion.exe
第二个参数包含一个完整的有空间的路径也是如此。
当我通过命令行直接调用上述命令或在批处理文件中使用CALL
时,它正确执行该程序将打印出预期的输出。
现在,攻克执行我用后续批处理命令程序的输出
FOR /F "usebackq tokens=* delims=" %%i IN (`"D:\__My Program\___My Program\Folder1\Folder2\..\..\FileVersion\FileVersion\bin\Release\FileVersion.exe" /n "D:\__My Program\___My Program\Folder1\Folder2\bin\Deploy\My Program.exe"`) DO (
echo %%i
)
usebackq Use the alternate quoting style:
- Use double quotes for long file names in "filenameset".
- Use single quotes for 'Text string to process'
- Use back quotes for `command to process`
我认为我正确地做这个用反引号周围的命令,并在文件名周围使用引号。
然而,呼叫失败消息(德国翻译)
The command "D:\My" is either incorrect or couldn't be found.
我觉得这点与逃避的空间问题。
奇怪的部分:如果我要么替换要调用的exe的路径,要么使用路径为sans的空间,它的工作原理。因此,无论
FOR /F "usebackq tokens=* delims=" %%i IN (`FileVersion.exe /n "D:\__My Program\___My Program\Folder1\Folder2\bin\Deploy\My Program.exe"`) DO (
echo %%i
)
和
FOR /F "usebackq tokens=* delims=" %%i IN (`"D:\__My Program\___My Program\Folder1\Folder2\..\..\FileVersion\FileVersion\bin\Release\FileVersion.exe" /n Test.exe`) DO (
echo %%i
)
工作。
为什么两个引号转义的字符串不能在同一个命令中工作,我该如何解决?
我不知道,我看到使用反引号的宗旨! – Compo
看看[this](https://stackoverflow.com/q/22636308/2861476)是否解决了您的问题。 –
Compo:这没有什么区别。 @MCND你的。我确信必须有一个资源来回答它,但在筛选示例时我没有找到它。谢谢。我会将其标记为重复。 – Jens