Prevent unwanted redirection in compound piped command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MicrosoftIsKillingMe
Posts: 42
Joined: 11 Dec 2017 09:08

Prevent unwanted redirection in compound piped command

#1 Post by MicrosoftIsKillingMe » 18 Jun 2018 21:31

Rookie question. I have this line in my bootup batch

Code: Select all

fsutil 8dot3name query | for /F %%a in ('findstr /v /i "Enable "') do (echo DANGER FIX REGISTRY & pause)
The issue is that the pause does not pause. I suspect (but don't know) that the "pipe feeder" fsutil is piping to the pause.

Here's a simpler illustration that will work for all (because your installation may or may not "fail" the FINDSTR above):

Code: Select all

echo bad | for /F %%a in ('findstr /v /i "good"') do (echo Is not good & pause)
I THINK that the first echo is piping to the pause. Can I tweak this to not feed the "do block" ergo allowing the pause to pause? (Or is the issue with my syntax, meaning that there actually is no "unwanted redirection")

(FYI this is so that at boot I automatically check registry value NtfsDisable8dot3NameCreation, since some jerk update changed that without informing me or asking first. In case anyone's interested, it happened while running updates (on Win 7) suggested by the Dell "SupportAssist" utility, which wanted to update System Bios, and Intel Rapid Storage Technology Driver and Management, and two other Intel updates. However the very first thing it did was automatically do every urgent and nonurgent Windows Update, so it could have been that too. Whoever did it, that was pretty G.D. rude to do it at all, and not even at very least having the courtesy to give me a msgbox telling me.)

Squashman
Expert
Posts: 4178
Joined: 23 Dec 2011 13:59

Re: Prevent unwanted redirection in compound piped command

#2 Post by Squashman » 18 Jun 2018 22:29

Not understanding why you are using the FOR command. Why aren't you piping directly to FINDSTR /?

Code: Select all

fsutil 8dot3name query | findstr /v /i "Enable " >nul 2>&1 && (echo DANGER FIX REGISTRY & pause)
If you really want to put it all inside a FOR command then do so.

Code: Select all

for /F %%a in ('fsutil 8dot3name query ^|findstr /v /i "Enable "') do (echo DANGER FIX REGISTRY & pause)

MicrosoftIsKillingMe
Posts: 42
Joined: 11 Dec 2017 09:08

Re: Prevent unwanted redirection in compound piped command

#3 Post by MicrosoftIsKillingMe » 18 Jun 2018 22:48

Awesome. For understanding purposes, was I actually redirecting? One day I might pipe to FOR, and don't understand why this failed to pause but your solution didn't.

And BTW I understand going

Code: Select all

>nul
but not

Code: Select all

>nul 2>&1



For me, code tags for single lines just interrupt the flow

Squashman
Expert
Posts: 4178
Joined: 23 Dec 2011 13:59

Re: Prevent unwanted redirection in compound piped command

#4 Post by Squashman » 18 Jun 2018 22:56


MicrosoftIsKillingMe
Posts: 42
Joined: 11 Dec 2017 09:08

Re: Prevent unwanted redirection in compound piped command

#5 Post by MicrosoftIsKillingMe » 18 Jun 2018 22:59

Just as an aside, I had tried to do something like your compact second form (which works), but I had tripped on the single quotes when I built it. I went
for /F %%a in ('fsutil 8dot3name query' ^| 'findstr /v /i "Enable "') do (echo DANGER FIX REGISTRY & pause)
which is faulty. (Removing the 2nd and 3rd single quote fixes it. Thanks for showing me.)

MicrosoftIsKillingMe
Posts: 42
Joined: 11 Dec 2017 09:08

Re: Prevent unwanted redirection in compound piped command

#6 Post by MicrosoftIsKillingMe » 18 Jun 2018 23:13

>nul 2>&1 is still confusing. Rob's fine page covers 2>&1 redirecting to stdout and stderr but I don't know why that's done following >nul. It would seem you'd do either one or the other - either send to nul, or to the 2 standard devices.

Squashman
Expert
Posts: 4178
Joined: 23 Dec 2011 13:59

Re: Prevent unwanted redirection in compound piped command

#7 Post by Squashman » 18 Jun 2018 23:23

MicrosoftIsKillingMe wrote:
18 Jun 2018 23:13
>nul 2>&1 is still confusing. Rob's fine page covers 2>&1 redirecting to stdout and stderr but I don't know why that's done following >nul. It would seem you'd do either one or the other - either send to nul, or to the 2 standard devices.
All it is doing is redirecting standard output and standard error to the nul device. No different then what Rob show's on his webpage. He just uses a file as the example.

Post Reply