fastboot getvar from batch file

旧时模样 提交于 2019-12-11 18:49:57

问题


I was trying to get certain fastboot variables from a batch file. I was using something like :

for /f "tokens=2 delims=:" %%a in ('fastboot.exe getvar version-bootloader') do @echo version is %%a

But I get the output on command line, not in the variable %%a. the command 'fastboot.exe getvar version-bootloader' works perfectly in command-line. I also tried doing:

fastboot.exe getvar version-bootloader >> temp.txt

but temp.txt is always empty and i receive the output on the command line, instead of the file. Is there an alternative to this?


回答1:


fastboot output is directed to error stream, you can direct error stream to standard stream by adding 2>&1

  1. your script will get two lines since fastboot getvar returns additional line with time elapsed.
  2. your script parses the version with a leading space, you shoud add a space to the delimiter (it is default but when you give delims it is overwritten)

you should use:

for /f "tokens=2 delims=: " %%a in ('fastboot.exe getvar version-bootloader 2^>^&1 ^| findstr version') do @echo version is %%a


来源:https://stackoverflow.com/questions/10069543/fastboot-getvar-from-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!