2012-07-06 14 views
0

我的批處理腳本中有一個非常奇怪的錯誤。 雖然代碼使用Android調試橋,但我確定這是與cmd相關的錯誤,而不是adb。 所以,基本上如果有人在意,腳本只是檢查根訪問權限。下面的代碼的sniplet:批處理腳本:goto是意外的。使用find xyz file.log && goto pass ||轉到失敗

@echo off 
adb kill-server 
adb start-server 
adb shell "su" >check.log 2>&1 
adb kill-server 
"%windir%\system32\find.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%\system32\find.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%\system32\find.exe" "#" check.log >nul && SET tr=1 || SET tr=0 
if "%tr%"=="1" goto pass 
if "%tr%"=="0" goto fail 

我仍然得到goto的錯誤。 :/ 我很困惑,我之前使用過其他類似的語句。 感謝您的閱讀! :)

哦,SYSTEM32有時是不存在的路徑&,因爲這是被別人使用由,我需要使用%WINDIR%\ SYSTEM32 \

+1

這條線對我來說絕對好。如果您發佈了完整的批處理腳本,那麼我可以看到它沒有問題。這個腳本是否可以被另一個腳本調用?所以也許錯誤發生在另一個腳本中。 – 2012-07-06 14:49:37

回答

0

我跑你find線和它工作得很好我。嘗試使用%errorlevel%作爲一種解決方法,這也能正常工作在我的電腦

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

注意:您不需要指定find的完整路徑,如system32PATH變量。

希望這會有所幫助!

+0

不,不作爲批處理。 – user1506471 2012-07-06 14:35:52