Windows批处理文件上的IF语句问题

时间:2014-07-28 19:02:21

标签: windows if-statement

下面的Windows批处理文件代码旨在弄清楚某个进程是否正在运行。如果它正在运行它应该执行.exe然后等待7秒,最后返回到开头。如果进程未运行,则应等待30秒,然后再次检查。我遇到的问题是在IF语句之后执行任何操作。如果IF语句不正确,该程序似乎停止。因此,代码的其他部分永远不会被执行。我认为这可能是一个语法错误,但我找不到它。有什么建议?谢谢!

set %testx%="0"
:susbegin
for /f "tokens=1 delims=," %%F in ('tasklist /fo CSV /fi "Imagename eq Bentley.lictransmit.exe" /nh') do set testx=%%F

if %testx%=="Bentley.lictransmit.exe" goto susexe

ping 192.0.0.0 -n 1 -w 30000 > nul 
goto susbegin

:susexe 
pssuspend -r Bentley.lictransmit.exe 
ping 192.0.0.0 -n 1 -w 7000 > nul 
set %testx%="0" 
goto susbegin 
:end

1 个答案:

答案 0 :(得分:0)

您需要%testx%周围的引号,如下所示:

if "%testx%"=="Bentley.lictransmit.exe" goto susexe

此外,在开头和结尾时,您应该在设置时引用它。

这是错误的:

set %testx%="0"

应该是:

set testx="0"