2015-07-13 169 views
0

我有以下命令和輸出:批量解析命令輸出

d:\adb>adb shell service call iphonesubinfo 1 
Result: Parcel(
    0x00000000: 00000000 0000000f 00350033 00380039 '........8.5.9.8.' 
    0x00000010: 00320037 00360030 00350032 00310034 '7.2.0.1.2.4.4.1.' 
    0x00000020: 00390039 00000039     '5.9.9...  ') 

我怎麼能分析它,並在同一行只得到IMEI?

也:

< waiting for device > 
... 
(bootloader) --------------------------------------------------------- 
(bootloader) Device-ID 
(bootloader) 2FC9A68923FD175AA6E13657181CA6AB 
(bootloader) 4AE438F12376AFA85D0E3467AE83A752 
(bootloader) --------------------------------------------------------- 
OKAY [ 0.020s] 
finished. total time: 0.020s 

得到的序列爲:2FC9A68923FD175AA6E13657181CA6AB4AE438F12376AFA85D0E3467AE83A752

回答

3

請注意,在 「代碼」

@echo off 
REM Spliting the IMEI multiline output to lines 
SETLOCAL ENABLEDELAYEDEXPANSION 
SET count=1 
FOR /F "tokens=* USEBACKQ" %%F IN (`adb shell service call iphonesubinfo 1`) DO (
    SET var!count!=%%F 
    SET /a count=!count!+1 
) 

REM From each output line of interest we take the IMEI "string" portion 
for /f "tokens=6" %%G IN ("%var2%") DO SET v1=%%G 
for /f "tokens=6" %%G IN ("%var3%") DO SET v2=%%G 
for /f "tokens=4" %%G IN ("%var4%") DO SET v3=%%G 

REM Stiching the IMEI parts to one string 
SET imei=%v1%%v2%%v3% 
SET imei=%imei:'=% 
SET imei=%imei:.=% 
ECHO %imei% 

ENDLOCAL 
+0

我REM評論偉大的工作,謝謝你,我會試着去了解過程 –

+1

本質上,REM評論描述流程/過程。如果您的社區BKM –

+0

能幫助您解決第二個問題,請同樣接受答案。 –