1

I am very new to batch scripting. I am trying to ask the user to input a known variable from the first row of a text file called camera.txt.

camera.txt contains:

cam52 http://192.168.101.52/reboot.cgi?delay=555

cam53 http://192.168.101.53/reboot.cgi?delay=555

If user inputs cam52 it would proceed to start IE with the second row's value "column two in text file"

I have the following thus far but unsure if I am even in the right path...

 @echo off

 Title Input Camera and Reboot

  ECHO input camera to restart

 ......?

 FOR /f "tokens=2 delims= " %%b IN (camera.txt) DO ECHO Launching Internet  Explorer with camera URL %%b

 Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" "%%b"

What do I make it to work?

MikeyNike
  • 13
  • 2

1 Answers1

1

Let's start with getting user input.
From In Windows cmd, how do I prompt for user input and use the result in another command?

set /p id="Enter ID: "

Second, looping throught the file.

You've already got this close to figured out. Kudos. However, we need to get both pieces of the line. tokens=2 will just get the second piece (the URL). So we will change it a bit...

FOR /f "tokens=1,2 delims= " %%a IN (camera.txt) DO 

See http://ss64.com/nt/for_f.html for more info on this.


Third, a comparison.

From ss64's if documentation:

IF %ERRORLEVEL% EQU 2 goto sub_problem2

Fourth, opening the page/browser

From another SO question: Open a Web Page in a Windows Batch FIle

start "" http://www.stackoverflow.com

Summary

So, if we add all those together, we get something like this:

@echo off
REM Title Input Camera and Reboot

set /p cam="input camera to restart: " 

FOR /f "tokens=1,2 delims= " %%a IN (camera.txt) DO (
    if %%a EQU %cam% (
        ECHO Launching Internet Explorer with camera URL %%b
        start "" %%b
    )
)
Community
  • 1
  • 1