批处理脚本:转到是意外的。使用查找 XYZ 文件.log &&goto pass ||转到失败



我的批处理脚本中有一个非常奇怪的错误。尽管代码使用Android调试桥,但我确定这是与cmd而不是adb相关的错误。因此,基本上如果有人关心,脚本只会检查root访问权限。这是代码的片段:

@echo off
adb kill-server
adb start-server
adb shell "su" >check.log 2>&1
adb kill-server
"%windir%system32find.exe" "#" check.log && goto pass || goto fail
:fail
echo No root access!
pause
:pass
echo Root access detected!
pause

此输出为:

* daemon not running. starting it now on port XXXX *
* daemon started successfully *
* server not running *
---------- CHECK.LOG
goto was unexpected at this time

窗口会自动关闭。

如果我通过手动键入命令在命令窗口中运行它,这就是我得到的:

J:tools>adb kill-server
J:tools>adb start-server
* daemon not running. starting it now on port XXXX *
* daemon started successfully *
J:tools>adb shell su >check.log 2>&1
J:tools>"%windir%system32find.exe" "#" check.log && echo pass || echo fail
---------- CHECK.LOG
fail

谁能想到解决方案?我尝试这样做:

@echo off
adb kill-server
adb start-server
adb shell "su" >check.log 2>&1
adb kill-server
SET tr=0
"%windir%system32find.exe" "#" check.log >nul && SET tr=1 || SET tr=0
if "%tr%"=="1" goto pass
if "%tr%"=="0" goto fail

我仍然收到转到的错误。我很困惑,我以前使用过其他这样的陈述。感谢您的阅读!:)

哦,system32 有时不存在于路径中,因为它是供其他人使用的,我需要使用 %windir%\system32\

我运行了你的find行,它对我来说效果很好。尝试使用 %errorlevel% 作为解决方法,这在我的电脑上也可以正常工作

find "#" check.log
if %errorlevel%==0 goto pass
if %errorlevel%==1 goto fail

注意:您不需要指定 find 的完整路径,因为system32位于 PATH 变量中。

希望这有帮助!

最新更新