Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Why doesn't this work ?
[batch.bat]
echo %1[tmp.txt]
dummyc:\batch.bat
This does not print "dummy" as I would expect. Can one tell me how to do so ?
/T

I think he created those two files discribed on his first message, then tryed:
batch.bat < tmp.txt
And he expected that the batch script got the string in the text file as first parameter.
Why it doesn't work? Well... because it's just not supposed to hehe... Batch files don't read input from stdin, like some .exe and .COM applications. Instead, do this:
[batch.bat]
for /F %%A in (tmp.txt) do echo %%A[tmp.txt]
dummyFor more information, type "FOR/?" on the command prompt. Pay attention to the part talking about the /F switch.
Keep in mind that this FOR/F thing will only work on NT systems, not on Win9x nor DOS (there are other methods for those OS's).
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

my my....no need go through all those crazy solutions...your problem is simple.
Problem: used "echo %1" in batch file.
reason: This causes it to "echo tmp.txt" and prints the name of the file, if anything. What you want is the contects of the file.Solution: replace "echo %1" with "type %1". Type dumps the contents of the text file specified.

Well, that prooves how UNclear the original poster were. If he just wanted to display the contents of the text file, Chad is right, it is simple as that. However, if he wants to use the string on the text file as a variable (and that's what I thought he meant), it takes other procedures (like the one I described). Just using TYPE won't do it.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

Ok, my first request was probably not clear. Sorry for that.
What I want, is to have the batch file arguments taken from a file:
you usually do :
batch.dat %1 %2 %3I want %1 %2 %3 to be taken from a file that contains %1 %2 %3.
The answer from Secret_Doom is good, but still not enough. I have to be able to SHIFT %1 %2 %3 and so on. Using the FOR command implies major limitation - as far as I could see, when trying to assign a variable in the loop (expansion pbs)-.
By the way, thank you all for helping me.

That's much more clear, Tierry.
You see that you can get the strings to environment variables (like %ONE% or %TWO%, but not yet %1 or %2) with the FOR cmd, right? So, call a subroutine with those variable as parameters, so they will become parameters for the subroutine. Here's an example:
[temp.txt]
The dog is running
Why is the cat still?[script.bat]
@echo off
if "%1"=="GoTo" goto %2
for /F "tokens=*" %%A in (temp.txt) do call %0 GoTo process %%A
goto eof
:process
if "%3"=="" goto eof
echo %3
shift
goto process
:eofThis subroutine thing is kinda difficult to understand on the begginning, but it's very useful. You could do the same thing with two batch scipts, calling the second from the first. But then, you need two files! With this subroutine thing, it's like you have both files on the same one.
Anyway, the output from that script would be:
The
dog
is
running
Why
is
the
cat
still?But all those were once represented by %3.
Is that what you wanted?
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br_______________________________________________________

![]() |
![]() |
![]() |

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