这是我遇到的问题:
@ECHO OFF
REM If this batch file is run in the same directory as "command.exe" then the
REM following line will work.
FOR /F "usebackq" %%A IN (`command.exe "C:\File Being Passed as a Parameter.txt"`) DO ECHO %%A
REM The following line does not work no matter where this batch file is run.
FOR /F "usebackq" %%A IN (`"C:\Folder With Spaces\command.exe" "C:\File Being Passed as a Parameter.txt"`) DO ECHO %%A
Run Code Online (Sandbox Code Playgroud)
我想将这个批处理文件存储在任何我想要的地方,而不是强制将它存储在与command.exe相同的文件夹中.有什么建议?
And*_*y M 27
CALL在程序名称前添加:
FOR /F "usebackq" %%A IN (`CALL "C:\Folder With Spaces\command.exe" "C:\File Being Passed as a Parameter.txt"`) DO ECHO %%A
Run Code Online (Sandbox Code Playgroud)
jeb*_*jeb 13
Andriy M的call诀窍是聪明且工作正常,但我试图在这里理解这个问题.
这个问题是由cmd.exe你所读到的,正如你所读到的那样cmd /help
....
当行中没有两个引号时,将删除第一个和最后一个引号.
...
因此,还有另一种解决方案,只需添加两个额外的引号
FOR /F "usebackq=" %%A IN (`""C:\Folder Space\myCmd.exe" "Param space""`) DO (
ECHO %%A
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12646 次 |
| 最近记录: |