You are not logged in.

#1 12 Dec 2020 19:25

pappaG
Member
Registered: 04 Jan 2020
Posts: 6

post the batch files we use

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

#2 15 Dec 2020 13:23

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: post the batch files we use

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 smile


cmd | *sh | ruby | chef

Offline

#3 15 Dec 2020 17:08

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: post the batch files we use

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

#4 20 Dec 2020 00:38

pappaG
Member
Registered: 04 Jan 2020
Posts: 6

Re: post the batch files we use

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

Board footer

Powered by