batch file - How to open a program using user input -
i writing program open program when user types in: "open chrome" open chrome. have this:
set /p start=what should do? if /i "%start%"==" open calculator" goto calculator
:calculator start c:\windows\system32\calc.exe
so @ calculator starts program calculator. want user type in "open" , code knows "open" = "start" , whatever comes next has open.
so code takes apart user types in if type in "open" turns start , puts in code so: set /p "input= "
%input% + %input2.exe
first thing user types in equals input , second thing user types in equals input2 can type in start calc , code be: start calc.exe because it's added .exe in second word user types in.
when give me answer can please explain each bit does?
@echo off setlocal :nextcommand echo/ set /p "input=what should do? " if /i "%input%" equ "exit" ( echo bye... exit /b ) rem try change "open" "start" in input line set "changed=%input:open=start%" rem check if input changed if "%changed%" equ "%input%" ( echo don't know how %input% goto nextcommand ) rem execute changed line adding ".exe" @ end %changed%.exe echo done! goto nextcommand
Comments
Post a Comment