“)此时出乎意料” - 批处理脚本

时间:2016-05-19 09:14:06

标签: batch-file

我从snippet脚本获得此代码batch。脚本失败了:

  

“)此时出人意料”

SETLOCAL EnableDelayedExpansion

set var="value "
    echo !var!
    IF "!var!"=="value " (
        echo Perfect )

P.S。我需要在我的脚本中使用Delayed Expansion

1 个答案:

答案 0 :(得分:0)

你发布的摘录没有错误信息。尽管你想在变量名中包含最后的空格,你可以使用这样的引号:

@echo off
SETLOCAL EnableDelayedExpansion

set "var=value "
    echo !var!
    IF "!var!" == "value " (
        echo Perfect )

基于赞扬编辑:

@echo off
setlocal enableDelayedExpansion
for /f "usebackq" %%f in (`"wmic process where name='java.exe' get commandline /format:value"`) do (
    call ::run  "%%~f"
)

:run
for /f "tokens=7" %%# in ("%%~1") do set "var=%%#"  
echo "!var!" 
IF "!var!"=="someValue " ( 
    echo Already running 
) Else (
 echo S

淋上 )