Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell FindStr不是';我工作不正常_Shell_Batch File_Findstr - Fatal编程技术网

Shell FindStr不是';我工作不正常

Shell FindStr不是';我工作不正常,shell,batch-file,findstr,Shell,Batch File,Findstr,我制作了一段批处理代码,我认为这会起作用。我认为这段代码在做什么?我有一些插件,我想测试部署是否正确。所以我从plugins.txt获取pluginlink。然后我从SVN获得带有java语句的插件。我部署插件并在test1.txt中获得反馈。然后我在那个文件中做一个findStr,搜索“buildsuccessful”,如果它在那里,我想添加BUILD-Gelukt,如果它失败,我想添加BUILD-Fout。但是我总是得到Build Gelukt的答案,正如你在他发回的图片中看到的,Build

我制作了一段批处理代码,我认为这会起作用。我认为这段代码在做什么?我有一些插件,我想测试部署是否正确。所以我从plugins.txt获取pluginlink。然后我从SVN获得带有java语句的插件。我部署插件并在test1.txt中获得反馈。然后我在那个文件中做一个findStr,搜索“buildsuccessful”,如果它在那里,我想添加BUILD-Gelukt,如果它失败,我想添加BUILD-Fout。但是我总是得到Build Gelukt的答案,正如你在他发回的图片中看到的,Build失败了

这段代码有什么问题

for /f "tokens=* delims= " %%a in (plugins.txt) do (
echo %%a
cd "C:\dotCMS Automatic Install"
java -cp .;"C:\dotCMS Automatic Install\svnkit.jar" Test %%a
cd %dotcms_home%
call ant deploy-plugins > test1.txt
FindStr "SUCCESSFUL" test1.txt
if %ERRORLEVEL% ==1 (echo ^<tr BGCOLOR=\"#FFFFFF\"^>^<td^>%%a^</td^>^<td^>Build Fout^</td^>^</tr^> >> C:\dotCMSResults\goedje.html ) else (echo ^<tr BGCOLOR=\"#00FF00\"^>^<td^>%%a^</td^>^<td^>Build Gelukt^</td^>^</tr^> >> C:\dotCMSResults\goedje.html) 
del test1.txt
rem call ant undeploy-plugins >> test.txt
)
for/f“tokens=*delims=“%%a in(plugins.txt)do(
回声%%a
cd“C:\dotCMS自动安装”
java-cp.“C:\dotCMS自动安装\svnkit.jar”测试%%a
cd%dotcms\u home%
调用ant deploy plugins>test1.txt
FindStr“成功”test1.txt
如果%ERRORLEVEL%==1(echo^^%%a^^^^^>>C:\dotCMSResults\goedje.html)其他(echo^^%%a^^^^^^ Build Gelukt^^>>C:\dotCMSResults\goedje.html)
del test1.txt
rem调用ant取消部署插件>>test.txt
)

变量
%ErrorLevel%
仅适用于上一个命令

所以当你这样做的时候:

echo Errorlevel: %ERRORLEVEL%
使用当前代码,您将获得上面
CD
命令的错误级别


尝试在
FindStr
命令后立即放置
if%ERRORLEVEL%==1
行,然后执行del和cd。显然,您需要将html文件的完整路径放在echo语句中。

经典批处理问题-您正在设置ERRORLEVEL,并试图在同一
DO()
子句中使用
%ERRORLEVEL%
访问它<代码>%VAR%扩展在解析时发生,而整个
的。。。DO()
语句被解析一次,因此您可以在执行该语句之前看到ERRORLEVEL的值。显然这行不通

杰布在评论中提到了关于消失的引用的答案。如果您
在顶部设置Local enableDelayedExpansion
,然后使用
,您的问题将得到解决!错误等级而不是
%ERRORLEVEL%
。此外,GregHNZ的正确之处在于ERRORLEVEL测试应该在FINDSTR语句之后立即进行

处理括号内的ERRORLEVEL还有其他不需要延迟扩展的方法:

如果ERRORLEVEL大于或等于1,则执行以下测试

IF ERRORLEVEL 1 (...) ELSE (...)
和下面的命令根据先前命令的结果有条件地执行命令

FindStr "SUCCESSFUL" test1.txt && (
  commands to execute if FindStr succeeded
) || (
  commands to execute if prior command failed.
)

顺便说一句,对于更简单的回显html代码,您可以使用。像
echo!“=!%%aBu…
@jeb这对我不起作用=我还是得到了!”!属于在html文件中。好的,我忘了提到之前需要启用延迟扩展,使用
setlocal enabledayedexpansion
。我更改了代码,并在第一篇文章中设置了它。。但它仍然不起作用。。在findStr语句之后,我只测试了一个Echo%ERRORLEVEL%。但他总是打出0。虽然命令行中的文本表示部署失败。@GregHNZ:%ERRORLEVEL%未给出CD命令的错误级别。它在解析FOR语句之前给出值!但是错误级别测试应该在FINDSTR语句之后立即进行,这是正确的。