You are not logged in.
Pages: 1
I've been referring to this site for over a decade, and it's the best one out there. I was curios if there is a place that has examples of batch files people use from the short one liners to the complex? there are sites that people go to, that they ask how do you do this and get the short answer of here is the way to do it.
But there are other ways of doing things that I would like to learn. for an example
tasklist | find /c "notepad" > G:\note.txt
set /p count= <G:\note.txt
as compared to
for /f "tokens=*" %a in ('tasklist ^| find /c "notepad"') do set count=%a
one outputs a text file and then reads the text and puts it in a varible.
the other queries and sets the varible without more writes to the disk
the end result is the same but why would someone choose the former?
Great site and thanks,
Offline
I suppose the first form could be useful if you already are writing out to file for some other reason.
Personally speaking, I'd go for the second form every time (even if I already had the file, as that could also be ingested with a minor change).
As for why someone else might make a different choice, I'm afraid I can't offer much insight into other people's mental processes
cmd | *sh | ruby | chef
Offline
I could see needing to run the second version if you've somehow managed to get the script into a folder where you currently don't have write permissions (or in this example, if you're running it on a computer where G: doesn't exist).
Offline
Thank-you both for your replies.
all of my learning is from sites where people would give you a one liner to fix the problem, so the batch files I use day to day are just cobbled together one liners and I was wondering if some of them might be posted to possibly help someone else or help me to improve by finding a better way of doing things.
Thanks again.
Last edited by pappaG (20 Dec 2020 00:46)
Offline
Pages: 1