How do you strip quotes out of an ECHO'ed string in a Windows batch file?

后端 未结 12 1873
萌比男神i
萌比男神i 2020-12-05 04:23

I have a Windows batch file I\'m creating, but I have to ECHO a large complex string, so I\'m having to put double quotes on either end. The problem is that the quotes are

12条回答
  •  旧巷少年郎
    2020-12-05 05:06

    Daniel Budzyński's response is brilliant. It works even in situations where there are special characters in the output. For example:

    C:\> for /f "usebackq tokens=2 delims=:" %i in (`%comspec%\..\ping -n 1 -w 200 10.200.1.1 ^| \
         findstr /c:"TTL="`) do echo|set /p="%i"
    
    bytes=32 time<1ms TTL=255
    

    If you try tried a simple echo without the quotes, you get a error, due to the "<" in the variable:

    C:\> set "output=bytes=32 time<1ms TTL=255"
    C:\> echo %output%
    The system cannot find the file specified.
    
    C:\> echo|set /p="%output%"
    bytes=32 time<1ms TTL=255
    

提交回复
热议问题