halcyon27
halcyon27

Reputation: 169

Get user input to install file

I'd like to be run this file and see

"1 for example_x 2 for example_y 3 for example_z

Enter number for apk to install:"

Then I press 1, 2, or 3 and enter and the script installs the corresponding .apk via adb (Android Debug Bridge).

When I run this now, I get the message "can't find '1' to install".

@echo off

set newline=^& echo.

set 1=example_x.apk
set 2=example_y.apk
set 3=example_z.apk

echo 1 for example_x %newline% 2 for example_y% 3 for example_z %newline%

set /p UserInput= Enter number for apk to install: 

adb install %UserInput%

pause
exit

Upvotes: 1

Views: 55

Answers (1)

Monacraft
Monacraft

Reputation: 6630

Ok, for your situation the choice command is what you are lookign for (use it in everycase possible). Here is what you need to do to your code:

(Also the problem is not with your command, it is when you use adb install %UserInput% look at the soloution)

Code :

@echo off
setlocal enabledelayedexpansion

set newline=^& echo.

set 1=example_x.apk
set 2=example_y.apk
set 3=example_z.apk

echo 1 for example_x %newline% 2 for example_y% 3 for example_z %newline%

choice /c 123 /n /m "Enter number for apk to install: "
set UserInput=%errorlevel%

adb install !%UserInput%!

pause
exit

Explanation of choice and !%UserInput%! :

Choice:

  • /n specify's not to display "[1,2,3}" (which you have already done)
  • /c Specify Opitions
  • /m "" Text to display

!%UserInput%!:

  • set UserInput=%errorlevel% where %errorlevel% is the ouput of the choice command
  • !%UserInput%! this only works if you setlocal enabledelayedexpansion and means, whatever result you get from %UserInput% is then treated as a variable itself. (! is treated the same as a %)

Hope this helped, to learn more, type the command followed by /?

Yours Mona

Upvotes: 2

Related Questions