Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i reuse variable set in a FOR /f ??

252 views
Skip to first unread message

Yannick Ambert

unread,
Jan 4, 2000, 3:00:00 AM1/4/00
to
Hello,

i have wrote this batch file and the result is not good :

for /f "tokens=1" %%a in (.\list3.trc) do (
set NAME=%%a
echo %NAME%
pause)


the file list3.trc contain program names.
Why the echo %NAME% doesn't return all the program names ??

the execution result is :

FOR /F "tokens=1" %a in (.\list3.trc) do (set NAME=%a & echo &
pause)

(set NAME=dudley_editinv & echo & pause)
ECHO is on.
Press any key to continue . . .

(set NAME=dudley_inventaire & echo & pause)
ECHO is on.
Press any key to continue . . .

Please help me...


NOTA : I don't want to simply display the name but i want to make task
with this name.....
I know that the following file work fine :
for /f "tokens=1" %%a in (.\list3.trc) do echo %%a


Walter Zackery

unread,
Jan 4, 2000, 3:00:00 AM1/4/00
to

NT processes a command line by expanding all environmental variables
BEFORE executing the line. That means that if you set a variable and
then try to echo that variable on the same command line, then the
value that will be echoed is the value of the variable as it was on
the previous command line. If the variable wasn't set, then you'll see
the message that you're seeing: ECHO is on. One workaround for this is
the following command line.

for /f "tokens=1" %%a in (.\list3.trc) do (
set NAME=%%a

for /f "tokens=2 delims==" %%b in (
'set^|findstr/b /i "name="') do echo %%b
pause)

"Yannick Ambert" <yam...@sls.fr> wrote in message
news:3871d6f9...@news.cornut.fr...
: Hello,

:

Mark Stang

unread,
Jan 4, 2000, 3:00:00 AM1/4/00
to

"Walter Zackery" <walter_...@my-Deja.com> wrote in message
news:84te3v$7fv2$1...@newssvr03-int.news.prodigy.com...

>
> NT processes a command line by expanding all environmental variables
> BEFORE executing the line. That means that if you set a variable and
> then try to echo that variable on the same command line, then the
> value that will be echoed is the value of the variable as it was on
> the previous command line. If the variable wasn't set, then you'll see
> the message that you're seeing: ECHO is on. One workaround for this is
> the following command line.
>
> for /f "tokens=1" %%a in (.\list3.trc) do (
> set NAME=%%a
> for /f "tokens=2 delims==" %%b in (
> 'set^|findstr/b /i "name="') do echo %%b
> pause)
>

Another way is

for /f "tokens=1" %%a in (.\list3.trc) do call :sub
goto :eof

:sub
set NAME=%%a
echo %NAME%
pause
goto :eof

Bennett Benson

unread,
Jan 4, 2000, 3:00:00 AM1/4/00
to
I see from using the pause that this is going to be an interactive
script. This makes speed a non-issue. However, if you need this to run
in a non-interactive mode, you'll find the following to be
significantly faster. Just remove the pause and time it.

Bennett Benson

for /f "tokens=1" %%a in (.\list3.trc) do call :sub1 %%a
goto end
:sub1
set NAME=%1
echo %%b
pause
goto :eof
:end

On Tue, 4 Jan 2000 13:29:02 -0500, "Walter Zackery"
<walter_...@my-Deja.com> wrote:

>
>NT processes a command line by expanding all environmental variables
>BEFORE executing the line. That means that if you set a variable and
>then try to echo that variable on the same command line, then the
>value that will be echoed is the value of the variable as it was on
>the previous command line. If the variable wasn't set, then you'll see
>the message that you're seeing: ECHO is on. One workaround for this is
>the following command line.
>
>for /f "tokens=1" %%a in (.\list3.trc) do (
>set NAME=%%a
>for /f "tokens=2 delims==" %%b in (
>'set^|findstr/b /i "name="') do echo %%b
>pause)
>
>
>

0 new messages