Computing.Net > Forums > Programming > Batch File Help!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch File Help!

Reply to Message Icon

Name: 01yraunaj
Date: December 28, 2008 at 11:27:11 Pacific
OS: Windows XP
CPU/Ram:
Product: Hewlett-packard /
Comment:

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:e9

Any suggestions or examples would be greatly appreciated. Thanks for your time.



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: December 29, 2008 at 05:05:33 Pacific
Reply:

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


0

Response Number 2
Name: Holla
Date: December 29, 2008 at 05:14:12 Pacific
Reply:

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.


0

Response Number 3
Name: IVO
Date: December 29, 2008 at 05:19:03 Pacific
Reply:


@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 (").


0

Response Number 4
Name: Mechanix2Go
Date: December 29, 2008 at 05:38:15 Pacific
Reply:

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


0

Response Number 5
Name: 01yraunaj
Date: December 29, 2008 at 08:29:34 Pacific
Reply:

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!


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: December 29, 2008 at 10:22:18 Pacific
Reply:

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


0

Response Number 7
Name: reno
Date: December 30, 2008 at 05:12:35 Pacific
Reply:

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 No

on question no 1.
"cleartool lsview [variable]" what does this command do?


0

Response Number 8
Name: reno
Date: December 30, 2008 at 05:17:03 Pacific
Reply:

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


0

Response Number 9
Name: 01yraunaj
Date: December 30, 2008 at 06:38:16 Pacific
Reply:

Reno,

The command is specific to some IBM software I am using...


0

Response Number 10
Name: 01yraunaj
Date: December 30, 2008 at 06:54:24 Pacific
Reply:

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 No

Pause

Thanks for your help!


0

Response Number 11
Name: reno
Date: December 30, 2008 at 09:37:12 Pacific
Reply:

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


0

Response Number 12
Name: Judago
Date: December 31, 2008 at 16:24:48 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

i need HDL code to conver... Batch Syntax Help



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Help!

batch file help www.computing.net/answers/programming/batch-file-help/13830.html

Batch File Help www.computing.net/answers/programming/batch-file-help-/11464.html

batch file help www.computing.net/answers/programming/batch-file-help/190.html