Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to create a batch file that will pull in variables from a text file (each variable is on a separate line).
The batch will need to execute a command in the windows command prompt similar to
"cleartool lsview [variable]". After the command is executed the one of two things will happen
(1) The command will run successfully and then proceed to substitute in the next variable.
(2) A prompt will appear asking for a " y / n" input followed by an "enter". At this point I would like an "n" to be input and "enter" pressed. The batch should then proceed on with the next variable.
Example of text file:
f82e694y.f3134c13.918f.c4:b5:8k:83:b0:e1
3e5becn2.dpa74152.91de.2f:7a:3b:aa:d2:7w
8c1422c7.18i24c49.r87a.c4:df:79:74:ct:e9Any suggestions or examples would be greatly appreciated. Thanks for your time.

I'm pretty sure variable names can't contain : colons. Are the lines of text meant to be the variables of their contents. Variables can contain colons, but can't have them in their name:
set f:g=whatever <this won't work
set whatever=f:g <this will

01yraunaj,
1. The following works in vista. I have no xp test it out.
2. The choice command does not expect an enter after the user types in "y" or "n". Hope that is ok?
3. ctex.txt is the file that contains the variables. I assume there are no spaces in the variable.
4. Add @echo off at the beginning of the file if found to be working fine.setlocal enabledelayedExpansion
for /f %%a in (ctex.txt) do (
:Edit the next line to have your command.
echo cleartool lsview %%a
choice /c yn /m "Exit ?"
if !errorlevel!==1 (
echo inside Yes
goto :eof
) else (
echo inside No
)
)--
Holla.

@echo off
for /F %%j in ('type "%*"') do (
echo.n | cleartool lsview %%j
)
:: [End_Of_Batch]
Example of usage:
MyBatch C:\My Folder\list.txt
where the path/filename must not be embedded by double quotes (").

Hi Judago,
This seems to work, but like you I have a queasy feling about it.
C:\temp\-\x-sim\ft>set z
z:z=a: s=========================================
Back to the original issue... To make the batch branch accordig to the result of the EXE, you need to test for the output of the EXE. We don't know what that is.
=====================================
If at first you don't succeed, you're about average.M2

Holla,
Whenever I execute a batch file similiar to the one you provided, I receive the following error:
"'Choice' is not reconized as an internal or external command, operable program or batch file."
Do you think this is something relative to XP? I can't seem to find much info on it..
Thanks everyone for your help!

CHIOCE was apparently left out of w2k but it thought it was included in XP.
=====================================
If at first you don't succeed, you're about average.M2

same as my xp, no choice command available.
instead i use this code:
Set /p c="Enter Yes or No (y/n)?"
for %%i in (y Y) if %c%==%%i echo Yes
for %%i in (n N) if %c%==%%i echo Noon question no 1.
"cleartool lsview [variable]" what does this command do?

miss out the do syntax =p
Set /p c="Enter Yes or No (y/n)?"
for %%i in (y Y) do if %c%==%%i echo Yes
for %%i in (n N) do if %c%==%%i echo No

So here's what I have so far...taking a bit from everyone's suggestions, but it's still not quite working properly.
Any suggestions?
setlocal enabledelayedExpansion
for /f %%a in ("C:\UUID.txt") do (
echo cleartool lsview %%a
)
Set /p c="Enter Yes or No (y/n)?"
for %%i in (y Y) if %c%==%%i echo Yes
for %%i in (n N) if %c%==%%i echo NoPause
Thanks for your help!

i think this is what you want to do in the batch file. try this code on test copy before doing it with real files.
@echo off & setlocal enabledelayedExpansion
for /f "tokens=* delims=" %%a in (c:\UUID.txt) do (
cleartool lsview %%a
call :choice
if !choice!==n goto :breakloop
)
:breakloop
Pause
goto :eof:choice
set choice=&Set /p choice="Proceed to next line ^(Y/N^)?"
for %%i in (N n) do if !choice!==%%i set choice=n&goto :eof
for %%i in (y Y) do if !choice!==%%i set choice=y&goto :eof
goto :choice

Here is my interpretation of the problem, which I admit I am still not entirely clear on.
@ECHO OFF
setlocal enabledelayedExpansion
for /f "usebackq delims=" %%a in ("c:\UUID.txt") do (
echo cleartool lsview %%a
set c=
call :decision datchk
:decision
if /i "%~1"=="datchk" (
Set /p c="Exit before proceeding (y/n)?"
if /i not "!c!"=="n" if /i not "!c!"=="y" goto decision
goto :eof
)
if /i "!c!"=="y" goto otherstuff
cleartool lsview %%a
)
:otherstuff
pause

![]() |
i need HDL code to conver...
|
Batch Syntax Help
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |