I'm trying to write a simple batch file to run the Tracert command, and the user can input if he wants a list of local devices to trace, in which case userResponse equals y, or if he doesn't, in which case it equals n. When I launch the application, the prompt to enter y or n appears and no matter what I write, the error message "if was unexpected at this time appears" and the screen quickly closes. After browsing Stack Overflow for a while, I tried the following fixes :
- Putting the text of the user inputs between quotes.
- Adding
SETLOCAL ENABLEDELAYEDEXPANSION
But none of those solutions worked.
Here's the code.
@echo off
color A
title Trace Route
SETLOCAL ENABLEDELAYEDEXPANSION
set /p userResponse="Would you like a list of local devices to trace (y/n)? "
if %userResponse%==y (
net view
set /p IPAddress="Enter the IP address that you would like to trace: "
echo.
set /p addressType="Enter the IP Address type (4 or 6): "
tracert -%addressType% %IPAddress%
PAUSE
) if %userResponse%==n (
set /p IPAddress="Enter the IP address that you would like to trace: "
echo.
set /p addressType="Enter the IP Address type (4 or 6): "
tracert -%addressType% %IPAddress%
PAUSE
)
I'm a beginner to Stack Exchange, so forgive me if any information is missing. I'll quickly add it on request.
Thanks!
Aucun commentaire:
Enregistrer un commentaire