Windows批处理:调用一个exe与内部的操作完全合格的路径包含空格 [英] Windows Batch: Invoke an exe with fully qualified path containing whitespaces inside of a for operation

查看:421
本文介绍了Windows批处理:调用一个exe与内部的操作完全合格的路径包含空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的代码片段:

  FOR / F令牌= 1,2 delims ==%% A有('%〜dp0otrtool \\ otrtool.exe%〜12 ^> ^&安培; 1)做回声%%一

如果脚本从路径称为无空格回声正常工作。为了使之成为工作的路径与空格我加各地的.exe报价:

  FOR / F令牌= 1,2 delims ==%% A有('%〜dp0otrtool \\ otrtool.exe%〜12 ^> ^ &功放; 1')做回声%%一

现在我的回声输出错误信息明镜Befehl。D:\\脚本\\ OTRTools \\ otrtool \\ otrtool.exe,测试IST entweder falsch geschrieben奥德konnte nicht gefunden werden 意思是错误的命令或文件名。如果我没有调用该行

 %〜dp0otrtool \\ otrtool.exe%〜12 ^> ^&放大器; 1

它工作正常。任何想法如何解决换线?


解决方案

  FOR / F令牌= 1,2 delims ==%% A有(CALL%〜dp0otrtool \\ otrtool.exe%〜12 ^> ^&放大器; 1')做回声%%一

插入呼叫似乎根治这个问题。

Consider the following snippet:

for /f "tokens=1,2 delims==" %%A in ('%~dp0otrtool\otrtool.exe "%~1" 2^>^&1') do echo %%A

The echo works fine if the script is called from a path without whitespaces. To make it work for paths with whitespaces I added quotes around the .exe:

for /f "tokens=1,2 delims==" %%A in ('"%~dp0otrtool\otrtool.exe" "%~1" 2^>^&1') do echo %%A

Now my echo outputs the error message Der Befehl "d:\Scripts\OTRTools\otrtool\otrtool.exe" "test" ist entweder falsch geschrieben oder konnte nicht gefunden werden. which means "Bad command or file name". If I invoke that line without for

"%~dp0otrtool\otrtool.exe" "%~1" 2^>^&1

it works fine. Any idea how to fix the for-line?

解决方案

for /f "tokens=1,2 delims==" %%A in ('CALL "%~dp0otrtool\otrtool.exe" "%~1" 2^>^&1') do echo %%A

inserting call seems to cure the problem.

这篇关于Windows批处理:调用一个exe与内部的操作完全合格的路径包含空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆