Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Adding commands after echo
Name: Credo Date: July 29, 2009 at 10:49:44 Pacific OS: Windows XP Subcategory: Batch
Comment:
Hello everyone, I was wondering if it's possible to add command code to be run on the same line as an echo.
IE:
ECHO Current number of lines: TYPE C:\files.txt
so I want to display "6 Downloaded" 6 being the value in files.txt.
I've tried this:
SET numfiles=0
DIR /a-d | FIND /c /i ".PRN" > NUMfiles.cnt
SET /P numfiles=<NUMfiles.cnt
ECHO %numfiles% Downloaded.>> C:\LOG\LOG_%curdate%.log
But It WILL NOT display the value pulled from the file.. I CAN'T FIGURE OUT WHY! The method works, and there is a value in the file - but for some reason when I try to write the output to the log file there's no number. All I get is:
Downloaded.
If anyone can tell my WHY it's not writing the value to the variable - and maybe another work around.
Name: Mechanix2Go Date: July 29, 2009 at 11:19:12 Pacific
Reply:
@echo off & setLocal EnableDELAYedExpansion
set num=
for /f "tokens=* delims= " %%a in ('dir/b/a-d *.prn') do ( set /a num+=1 ) echo number of prn files !num!
===================================== If at first you don't succeed, you're about average.
M2
0
Response Number 2
Name: Credo Date: July 29, 2009 at 11:24:33 Pacific
Reply:
Thanks, I'll try it.
What does the
& setLocal EnableDELAYedExpansion
do?
0
Response Number 3
Name: Credo Date: July 29, 2009 at 11:42:50 Pacific
Reply:
Thanks M2, that worked great!
I just don't understand why you used the "!" instead of the "%" for variables, and I know it didn't work until I added
& setLocal EnableDELAYedExpansion
to the @echo off...
Thanks again!
0
Response Number 4
Name: Mechanix2Go Date: July 29, 2009 at 12:17:26 Pacific
Reply:
!VAR! within setlocal clears the VAR when the bat quits. So you don't need to clean up.
===================================== If at first you don't succeed, you're about average.
M2
0
Response Number 5
Name: klint Date: July 30, 2009 at 02:20:48 Pacific
Reply:
I'd just like to add, when I tested Credo's original batch file, it worked. I don't know why it didn't work for you. Perhaps you have misspelt a variable in your batch file but spelt it correctly in your post.
Summary: regarding multiple strings and Set command? Try @echo off SET myText=COOL echo %myText% SET /P myText=Your message:- echo. echo "Your reply :- %myText%" Gives the following output:- COOL Your mess...
Summary: You can do it a couple ways. I would suggest gmoney's method as it's probably the easiest for a per-workstation method. What you'd want to do to prevent multiple installations is to just add a line to...
Summary: No, it's nothing to do with the 1>, that's quite normal. It's because > is shorthand for 1> so when the batch file echos the command, it echos it in full. 1> means "redirect standard output" and you c...